Referencing Shared Office Components
This content is no longer actively maintained. It is provided as is, for anyone who may still be using these technologies, with no warranties or claims of accuracy with regard to the most recent product version or service release.
Every Office application includes accessor properties that provide access to the shared Office components. For example, an Office application's Assistant property returns a reference to the Assistant object, the FileSearch property returns a reference to the FileSearch object, and the Scripts property returns a reference to the Scripts collection. From within any Office application, you can return a reference to a shared component object by using the appropriate accessor property; you don't need to use the New keyword to create an object variable that references the shared Office component.
Important All Office applications, except Microsoft Access, Microsoft FrontPage, and Microsoft Outlook, include a reference to the Microsoft Office 9.0 object library by default. Before you can work with shared Office components in Access, FrontPage, or Outlook, you must first manually set a reference to the Microsoft Office 9.0 object library.
As with any object model, before you can work with an object, you must either set an object variable to the object you want to work with or use the host application's accessor property. For example, the following code fragments illustrate using the accessor property (in these cases, the FileSearch, Assistant, and CommandBars accessor properties are used) to access various shared Office components.
With Application.FileSearch
.NewSearch
.LookIn = "C:\My Documents"
.FileName = "*.doc"
If .Execute() > 0 Then
' Work with found files here.
End If
End With
Dim objAssistant As Assistant
Set objAssistant = Application.Assistant
With objAssistant
.On = True
.Visible = True
.Animation = msoAnimationCharacterSuccessMajor
End With
Dim cbrCustomBar As CommandBar
Set cbrCustomBar = Application.CommandBars(strCBName)
With cbrCustomBar.Controls(strCtlName)
.Enabled = Not .Enabled
End With
****Important ****To set a reference to a shared Office component from outside an Office application, you must still use the accessor property of an Office application. For example, to set a reference to the FileSearch object from a Microsoft Visual Basic application, you could set a reference to the Word Application object and then use the Word FileSearch property to return a reference to the FileSearch object. For example:
Dim wdApp As Word.Application
Set wdApp = New Word.Application
With wdApp.FileSearch