6
votes

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
1
If addins have the same name but different folder path, have you delete the files of corresponding old ones? Or make the old ones inaccessible. Excel tends to use the old one if same name. - PatricK
Thanks for the suggestion @PatricK. This is probably a good thing to do generally, but the thing is that it happens even when no add-ins are installed at all (all previous add-ins are uninstalled and even removed from the folder). And when I open the Installer.xlsm file that installed them the correct add-ins are loaded (I see which files are being opened in Windows explorer). It's as if the add-ins are installed in the scope of the single xlsm file... - Tamara Aviv
Check the LoadBehavior setting in the registry to make sure it is 3 (load on startup) and not 2 (load on demand) or 0 (disabled). Also check the Disabled Items list to make sure Excel hasn't "quarantined" them. - Rachel Hettinger
Just a thought, if individual addin can check for Updates itself, wouldn't it be better? The addin update launches a new Excel process in safe mode, opens a variant of Installer, then exit the Excel the addin runs on. The installer variant then overwrites the local version of addin from a network source, then launch a new Excel process normally so the updated addins are running. then the variant closes itself. - PatricK

1 Answers

1
votes

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