Using the Office Object Model

The Office object library includes a set of objects for working with documents stored in document workspace sites and document libraries. You can use those objects from VBA, Visual Basic .NET, or C#.

The SharePoint objects are connected to the top-level Office document in each application. For example, the following lines get a reference to the document workspace in Excel, Word, and PowerPoint, respectively, from within VBA:

  • Set wsXL = ActiveWorkbook.SharedWorkspace

  • Set wsWord = ActiveDocument.SharedWorkspace

  • Set wsPPT = ActivePresentation.SharedWorkspace

From the document object, the SharePoint objects are organized as seen in Figure 12-1.

Office objects for SharePoint Services

Figure 12-1. Office objects for SharePoint Services

From VBA

Use the SharedWorkspace object to create, get, or delete a SharePoint document workspace site. The technique is the same for any of the supported document types. For example, to create a new workspace:

  1. Save the document.

  2. Call the SharedWorkspace object's CreateNew method to create the document workspace.

  3. Use the document's SharedWorkspace object to add members, tasks, links, files, or folders.

Table 12-3 lists frequently asked questions as a quick reference for VBA programming.

Table 12-3. SharePoint VBA quick reference

How do I?

Do this

Open a document library file?

Use the Open method and specify the document's web address.

Add a file to a document library?

Use the ...

Get Essential SharePoint 2007, 2nd Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.