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

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.

Microsoft® Word, Microsoft® Excel, and Microsoft® 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 Microsoft® Visual Basic® for Applications (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 Microsoft® Office XP 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 & addPpt.FullName _
                & vbCrLf
          Else
              strRegistered = strRegistered & _
                & 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

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."

See Also

Building Application-Specific Add-ins | Word Add-ins | Excel Add-ins | PowerPoint Add-ins | Access Add-ins | Adding and Removing Command Bars for Word, Excel, and PowerPoint Add-ins | Securing an Access, Excel, PowerPoint, or Word Add-in's VBA Project