Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Loading addins when Excel is instantiated programmatically

I am trying to create a new instance of Excel using VBA using:

Set XlApp = New Excel.Application

The problem is that this new instance of Excel doesn't load all the addins that load when I open Excel normally...Is there anything in the Excel Application object for loading in all the user-specified addins?

I'm not trying to load a specific add-in, but rather make the new Excel application behave as though the user opened it themself, so I'm really looking for a list of all the user-selected add-ins that usually load when opening Excel.

like image 902
Jon Fournier Avatar asked Oct 17 '08 18:10

Jon Fournier


People also ask

How do you make add-in load at startup Excel?

Then we can go to Registry Editor, try to navigate to HKEY_CURRENT_USER\Software\Microsoft\Office\Excel\Addins , find the addin and change its value of LoadBehavior to 3, it means the addin loaded at startup.

How do you make add-ins permanently in Excel?

Click the File tab, click Options, and then click the Add-Ins category. In the Manage box, click COM Add-ins, and then click Go. The COM Add-Ins dialog box appears. In the Add-Ins available box, select the check box next to the add-in that you want to install, and then click OK.

Could not load the Excel Add-Ins automatically?

Disabled Application Add-ins To solve the problem, select “Disabled Items” in the “Manage:” drop down at the bottom of the dialog and click “OK”. In the Disabled Items dialog select the add-in and click “Enable” and then close the dialog.

How do I run an addin in VBA?

Make sure that you click on the workbook you want to add the reference to, and from the VBA editor menu choose Tools -> References. In the displayed list check the box beside your renamed add-in, and then click on OK. You'll see that your workbook now has a new reference to the add-in.


2 Answers

I looked into this problem again, and the Application.Addins collection seems to have all the addins listed in the Tools->Addins menu, with a boolean value stating whether or not an addin is installed. So what seems to work for me now is to loop through all addins and if .Installed = true then I set .Installed to False and back to True, and that seems to properly load my addins.

Function ReloadXLAddins(TheXLApp As Excel.Application) As Boolean

    Dim CurrAddin As Excel.AddIn

    For Each CurrAddin In TheXLApp.AddIns
        If CurrAddin.Installed Then
            CurrAddin.Installed = False
            CurrAddin.Installed = True
        End If
    Next CurrAddin

End Function
like image 73
Jon Fournier Avatar answered Sep 29 '22 00:09

Jon Fournier


Using CreateObject("Excel.Application") would have the same result as using New Excel.Application, unfortunately.

You will have to load the Addins that you need individually by file path & name using the Application.Addins.Add(string fileName) method.

like image 44
Mike Rosenblum Avatar answered Sep 29 '22 01:09

Mike Rosenblum