views:

1275

answers:

1

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

+2  A: 

Almost all collections in VB(A) are 1-based. Your loop goes from zero, and so it'll fail when it tries to access AddIns(0). That's masked by the fact that you have On Error Resume Next.

Also, you'll need to explicitly remove the toolbar. Simply removing the add-in won't do that.

I can't say I like the way you're doing it, but it should work at least 50% of the time :-)

Gary McGill
The Add-in is now moved to the 'inactive application add-ins' section. It helps.
pancake