Work with Add-ins in Code

The previous VBScript sample in “Distribute the Add-in” demonstrates using Excel’s AddIn object to load an add-in as part of the installation process. That’s the primary use of the AddIns collection and AddIn object: loading, unloading, and enumerating add-ins.

For example, the following code lists the name and state of all the add-ins that are currently installed:

    Sub ListAddins( )
        Dim ad As AddIn
        Debug.Print "Title", "File name", "Loaded?"
        For Each ad In Application.Addins
            Debug.Print ad.Title, ad.FullName, ad.Installed
        Next
    End Sub

The Installed property determines whether installed add-ins are loaded in Excel—not whether they are installed on the user’s system as the name suggests. To load an add-in from code, set its Installed property to True. To unload it, set Installed to False. Use the Add method to install an add-in on the user’s system.

Get Programming Excel with VBA and .NET now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.