Loading an Excel Add-in
You can load a Microsoft® Excel add-in in one of three ways:
- **Manually **Select the check box next to the name of the add-in in the Add-Ins dialog box on the Tools menu.
- **Automatically when Excel starts **Save the add-in to the ..\ \Excel\XLStart subfolder. You can change the location of the XLStart subfolder on the General tab of the Options dialog box (Tools menu).
- **Programmatically **Use the Add method of the AddIns collection to add the add-in to the list of available add-ins, and then set the Installed property of the corresponding AddIn object to True.
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. Then, the procedure 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
See Also
Excel Add-ins | Creating an Excel Add-in | Running Code Automatically When an Excel Add-in Is Loaded or Unloaded