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 the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.