Microsoft Office 2000/Visual Basic Programmer's Guide   

Controlling Word, Excel, and PowerPoint Add-ins from Code

Word, Excel, and PowerPoint all have an AddIns collection that contains AddIn objects that correspond to application-specific add-ins. You can use these AddIn objects and the AddIns collections to control the behavior of application-specific add-ins from VBA.

Note that the AddIns collection and the COMAddIns collection are two separate collections. Both are returned by a property of the Application object: the AddIns property for application-specific add-ins, and the COMAddIns property for COM add-ins. However, the Office 9.0 object library provides the COMAddIns collection, while the AddIns collection is part of the host application's object model.

Although the AddIn objects and the AddIns collections for Word, Excel, and PowerPoint are similar, they each have different properties and methods. For example, each AddIn object has a read/write property that you can set to load or unload the add-in. In Word and Excel, this is the Installed property; in PowerPoint, it is the Loaded property.

The following code displays information about PowerPoint add-ins in a message box:

Sub DisplayPptAddins()
   ' This procedure displays information about add-ins currently
   ' registered and/or loaded in PowerPoint. To determine which
   ' add-ins are registered, VBA looks for add-ins in the registry.

     Dim lngNumAddIns      As Long
     Dim addPpt            As AddIn

     ' Used to build the dialog box.
     Dim strPrompt         As String
     Dim strRegistered     As String
     Dim strLoaded         As String
     Dim strTitle          As String

     ' Get the total number of add-ins.
     lngNumAddIns = PowerPoint.AddIns.Count

     Select Case lngNumAddIns
       Case 0
         ' No add-ins registered.
         strTitle = "No Add-ins"
         strPrompt = "You currently have no PowerPoint" _
          & " add-ins registered."
       Case 1
         ' One add-in registered.
         strTitle = "One Add-in Registered"
         strPrompt = addPpt.FullName
      Case Is > 1
         ' Set up the title for the dialog box.
         strTitle = lngNumAddIns & " Add-ins Registered"

         ' Determine which add-ins are loaded and/or registered.
         strLoaded = "Loaded: " & vbCrLf
         strRegistered = vbCrLf & "Registered: " & vbCrLf

         ' Loop through the AddIns collection.
         For Each addPpt In PowerPoint.AddIns
            ' Check Loaded property.
          If addPpt.Loaded = msoTrue Then
              strLoaded = strLoaded & vbCrLf & addPpt.FullName _
                & vbCrLf
          Else
              strRegistered = strRegistered & vbCrLf _
                & addPpt.FullName & vbCrLf
          End If
         Next addPpt
         ' Combine the loaded add-ins list with registered
         ' add-ins list.
         strPrompt = strLoaded & strRegistered
     End Select

     ' Display the dialog box.
     MsgBox strPrompt, vbInformation, strTitle
End Sub

The DisplayPptAddins procedure is available in the modEnumAddIns module in AddInObjects.ppt in the ODETools\V9\Samples\OPG\Samples\CH11 subfolder on the Office 2000 Developer CD-ROM.

For more information about using the AddIn object and AddIns collection, search the VBA host application's (Word, Excel, or PowerPoint) Visual Basic Reference Help index for "AddIn Object" and "AddIns collection."