Microsoft Office 2000/Visual Basic Programmer's Guide   

Loading an Excel Add-in

You can load an Excel add-in in one of three ways:

For example, the following procedure loads an add-in by first checking whether it is in the AddIns collection and adding it if it is not. The procedure then sets the add-in's Installed property to True. To call this procedure, pass in the path and file name of the add-in that you want to add:

Function Load_XL_AddIn(strFilePath As String) As Boolean
   ' Checks whether add-in is in collection, and
   ' then loads it. To call this procedure, pass
   ' in add-in's path and file name.

   Dim addXL            As Excel.AddIn
   Dim strAddInName     As String
   
   On Error Resume Next
   ' Call ParsePath function to return file name only.
   strAddInName = ParsePath(strFilePath, FILE_ONLY)
   ' Remove extension from file name to get add-in name.
   strAddInName = Left(strAddInName, Len(strAddInName) - 4)
   ' Attempt to return reference to add-in.
   Set addXL = Excel.AddIns(strAddInName)
   If Err <> 0 Then
      Err.Clear
      ' If add-in is not in collection, add it.
      Set addXL = Excel.AddIns.Add(strFilePath)
      If Err <> 0 Then
         ' If error occurs, exit procedure.
         Load_XL_AddIn = False
         GoTo Load_XL_AddIn_End
      End If
   End If
   ' Load add-in.
   If Not addXL.Installed Then addXL.Installed = True
   Load_XL_AddIn = True
   
Load_XL_AddIn_End:
   Exit Function
End Function

The Load_XL_AddIn procedure is available in the modAddInObjects module in AddInObjects.xls in the ODETools\V9\Samples\OPG\Samples\CH11 subfolder on the Office 2000 Developer CD-ROM.