Removing an Excel Add-in Using VBScript

I am trying to create an MSI installer that installs an add-in (.xla) in Microsoft Excel (2007 in my case). Installation is going well. I use "Custom Action", which 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 addin location to the script using the CustomActionData property. The add-in is copied to the folder inside the "Program Files", where it will remain until it is deleted. This is done by the installer.

The problem is that I am using an 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

Addin creates a custom toolbar in Excel u [installation. The toolbar is not deleted when deleted, and the add-in entry in the "Add-in" section in Excel settings is also not.

- , VBScript?

+3
2

VB (A) 1. , , AddIns(0). , On Error Resume Next.

, . .

, , , 50% : -)

+2
For Each Key in Keys
    objReg.EnumKey HKEY_CURRENT_USER,strRegPath & "\" & Key,xlKeys
    For Each xlKey in xlKeys
        if(LCase(xlKey) = "excel") Then
            objReg.EnumKey HKEY_CURRENT_USER,strRegPath & "\" & Key & "\" & xlKey,subKeys

            If(Not ISNULL(subKeys))  Then
                                For Each subKey in subKeys
                    If(lcase(subKey) = "options") Then          'Find Options subKey
                        objReg.EnumValues HKEY_CURRENT_USER, strRegPath & "\" & Key & "\" & xlKey & "\" & subKey, Values
                        If (Not IsNull(Values)) Then
                                     For Each oValue In Values
                                If (LCase(Left(oValue, 4))="open") Then
                                    objReg.GetStringValue HKEY_CURRENT_USER, strRegPath & "\" & Key & "\" & xlKey & "\" & subKey & "\", oValue, sTempValue
                                    If(Not XLAddinRemove(sTempValue)) Then

                                                                                If(aOpenKeyVals(0)<>"") Then
                                            Redim Preserve aOpenKeyVals(UBound(aOpenKeyVals)+1)
                                        End If
                                        aOpenKeyVals(UBound(aOpenKeyVals))=sTempValue
                                                                        End If
                                    objReg.DeleteValue HKEY_CURRENT_USER, strRegPath & "\" & Key & "\" & xlKey & "\" & subKey, oValue
                                End If
                            Next
                            For iOLoop = 0 To UBound(aOpenKeyVals)
                                If(iOLoop>0) Then sOpenName = "OPEN" & iOLoop
                                If aOpenKeyVals(iOLoop) <> "" Then
                                                                  objReg.SetStringValue HKEY_CURRENT_USER, strRegPath & "\" & Key & "\" & xlKey & "\" & subKey, sOpenName, aOpenKeyVals(iOLoop)
                                                                End If 
                            Next

                            sOpenName="OPEN"
                            Redim aOpenKeyVals (0)
                            aOpenKeyVals (0)=""
                        End If
                    End If
                 Next
            End If
          End If
    Next
Next
0

Source: https://habr.com/ru/post/1712655/