locked
Uninstalling Excel add-in using VBScript RRS feed

  • Question

  • I'm trying to create a MSI installer that installs an Add-In (.xla) into Microsoft Excel (2007 in my case). Installing it goes well. I use a 'Custom Action' that runs this VBScript file:

    Dim SourceDir 
    Dim objExcel 
    Dim objAddin 
     
    SourceDir = Session.Property("CustomActionData") 
    Set objExcel = CreateObject("Excel.Application") 
    objExcel.Workbooks.Add 
    Set objAddin = objExcel.AddIns.Add(SourceDir & "addin.xla", True) 
    objAddin.Installed = True 
    objExcel.Quit 
    Set objExcel = Nothing 
    

    I pass the location of the addin to the script using the CustomActionData property. The Add-in is copied to a folder inside 'Program Files', where it will stay until it is uninstalled. This is handled by the installer itself.

    The problem is when I use the uninstall script:

    Dim objExcel 
    Dim addin 
    On Error Resume Next 
     
    Set objExcel = CreateObject("Excel.Application") 
    For i = 0 To objExcel.Addins.Count 
        Set objAddin= objExcel.Addins.item(i) 
        If objAddin.Name = "addin.xla" Then 
            objAddin.Installed = False 
        End If 
    Next 
     
    objExcel.Quit 
    Set objExcel = Nothing 
    

    The addin creates a custom toolbar in Excel u[ installation. The toolbar is not removed upon uninstall, and the entry of the add-in in the 'Add-in' section of Excel's settings isn't either.

    Can anyone tell me if these two things can be done programmatically using VBScript?

    thanks in advance

    Wednesday, September 21, 2011 8:24 AM

Answers

  • Assuming the addin has a routine to remove menus when Excel closes it might be called in Sub Auto_Close(). In an automated instance that will not run automatically but you could do something like this

    On Error Resume Next
    Set objWb = objExcel.Workbooks("myAddin.xla")
    If Not wb Is Nothing Then
    wb.RunAutoMacros xlAutoClose
    End If
    ' existing code to uninstall the addin

    If that doesn't work you might need to write your own code to remove its menus

    Couple of points in passing -
    - Best to ensure Excel is not running before doing createobject() which you can test with GetObject

    - Uninstalling the addin does not remove it from the Addins collection, merely removes the tick in the addins manager such that it will load at start-up

    Peter Thornton

    • Marked as answer by Liliane Teng Tuesday, September 27, 2011 8:54 AM
    Wednesday, September 21, 2011 8:38 AM

All replies

  • Assuming the addin has a routine to remove menus when Excel closes it might be called in Sub Auto_Close(). In an automated instance that will not run automatically but you could do something like this

    On Error Resume Next
    Set objWb = objExcel.Workbooks("myAddin.xla")
    If Not wb Is Nothing Then
    wb.RunAutoMacros xlAutoClose
    End If
    ' existing code to uninstall the addin

    If that doesn't work you might need to write your own code to remove its menus

    Couple of points in passing -
    - Best to ensure Excel is not running before doing createobject() which you can test with GetObject

    - Uninstalling the addin does not remove it from the Addins collection, merely removes the tick in the addins manager such that it will load at start-up

    Peter Thornton

    • Marked as answer by Liliane Teng Tuesday, September 27, 2011 8:54 AM
    Wednesday, September 21, 2011 8:38 AM
  • Hi Peter,

    So is there a way to completly remove it from the addins collection?

    Thanks in advance.

    Yassine

    Wednesday, September 18, 2013 9:40 AM