Tamara Aviv
Tamara Aviv

Reputation: 925

Excel Add-ins installed programmatically are not loaded

Question Summary: Why do my add-ins which are installed programmatically do not load when I start Excel from Program Menu but are loaded when I open the Installer.xlsm workbook which installed them?

Details: My team develops a hierarchy of add-ins used by various users in our organization. I have an Installer.xlsm file which installs new versions for each of the add-ins. It has a Workbook_Open method which upon opening the workbook uninstalls currently installed versions of the add-ins and installs their newer versions.

This worked wonderfully for over a year. Recently we updated the hierarchy of the add-ins and since then the same script would run successfully, uninstalling old add-ins and installing new ones. However, when Excel is re-opened (from program menu or an existing workbook) it seems that the script had no effect at all - the add-ins that were installed before the run remain installed and the new add-ins are not even listed in the Manage Add-ins form. This is reflected also in HKCU\...\Excel\Add-in Manager - the list of add-ins remains identical to what it was before the run.

However, if I open Installer.xlsm again - it loads only the add-ins I'd expect it to load after a successful script run (loads the newly installed add-ins and doesn't load the ones the script uninstalled)! It's as if the add-ins are installed in the scope of the single .xlsm file...

Notes:

  1. The add-ins are not placed in Excel's Add-in directory but in a project folder (C:\appname\Addins\date).

  2. I use Excel 2010 on Windows 7 and have admin privilege on my machine.

  3. It's not a matter of Registry write access, since the same add-ins, if installed using the Excel UI are registered correctly under HKCU\...\Excel\Add-in Manager.

Please help resolve this mystery!

Code section which does the uninstalling:

    For Each ad In Application.AddIns
        For Each appName In pAppNames
            If pIniMap.item("FilePrefix").Exists(appName) Then
                filePrefix = pIniMap.item("FilePrefix").item(appName)
                If Left(ad.Name, Len(filePrefix)) = filePrefix Then
                    If ad.Installed Then
                        ad.Installed = False
                        Workbooks(ad.Name).Close False
                    End If
                End If
            Else
                logger.Warn "Entry is missing for section FilePrefix, appName=" & appName, methodName
            End If
        Next appName
    Next ad

Code section which does the installation of the add-ins:

For Each file In addinFiles
    curAddInPath = pAddinDir & file
    With Application.AddIns.Add(fileName:=curAddInPath)
        .Installed = True
    End With
Next file

Upvotes: 6

Views: 1534

Answers (1)

W-hit
W-hit

Reputation: 361

It may be that your adding from the default directory rather than the custom directory you specified. I added the argument below, in your installation code. Hopefully it helps.

For Each file In addinFiles
    curAddInPath = pAddinDir & file
    With Application.AddIns.Add(fileName:=curAddInPath, CopyFile:=False) 'add false to args if addin is not coming from default directory
        .Installed = True
    End With
Next file

Upvotes: 1

Related Questions