Improve company productivity with a Business Account.Sign Up

  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 439
  • Last Modified:

disable excel add-in

hi all,

I'm looking for information on how to script the removal of some excel add-in.

what I tried so far is some PowerShell that creates a COM object with excel.application, locates the add-in to remove and set it to not installed with:

($wb.Application.AddIns | Where-Object { $ -eq 'sapbex.xla' }).Installed = $false

but when I open excel, the add-in is still enabled.

is there someone here with more information on this, or that has a clue about what I am doing wrong?

thank you!
Daniel Brassard
Daniel Brassard
  • 3
2 Solutions
The standard way for an Excel addin is to set the Installed property to False (or True) to disabled (or enable) the addin.

 Sub Toggle_Analysis_AddIn()
   Dim A As AddIn
   For Each A In Application.AddIns
     If A.Name = "ANALYS32.XLL" Then
       A.Installed = Not A.Installed
       Exit Sub
     End If
 End Sub

Open in new window

 The same can be used for COMAddIns, if you have any.

 If Application.COMAddIns(1).Connect Then
    MsgBox "The add-in is connected."
    MsgBox "The add-in is not connected."
End If

Open in new window

There is a possibility that explains the behavior that you describe. If you disable the addin (also manually) in Excel and the addin is back if you reopen Excel, in fact means that something re-enables the addin. But that is not Excel.  The most reason for that are third party tools, which installs a service in windows (this is a running DLL in memory, not listed in the task manager). And that services forces the state of the addin.

Whenever you install an add-in in Excel, it is added to an internal list of available add-ins. This list is used by Excel whenever you display the Add-ins dialog box. (The Add-ins dialog box is where you are shown available add-ins and can use a check box to indicate which should be enabled when running Excel.) Removing a previously installed add-in so that it doesn't appear in the Add-ins dialog box can be a confusing process, since Excel provides no way to directly edit that internal list of add-ins. You can get around this frustration, however, by following these steps:

1. Get out of Excel.
2. Use the tools in Windows (such as the Search tool) to locate the add-in file you want removed. You can locate add-in files by their file name extension: either .xla or .xlam, depending on your version of Excel.
3. Delete, rename, or move the add-in file.
4. Start Excel. If the add-in was one that was automatically loaded when Excel first starts, you will get a message from Excel indicating that it cannot find your missing add-in file.
5. Answer Yes when prompted if you want to remove the add-in file from the list.
6. If the add-in was not one that started automatically, choose Add-Ins from the Tools menu. Excel displays the Add-Ins dialog box, and your deleted add-in should still be listed as available. (Remember; this dialog box represents the internal list of add-ins, and hasn't been updated.)
7. Select the check box next to the add-in you want deleted. This informs Excel you want to use the add-in.
8. Click on OK. You should get the same message described in step 4.
9. Answer Yes when prompted if you want to remove the add-in file from the list.
If none of the above works, it is possible to create a VBscript that deletes the registry key. Start the VBS shortly before you close Excel, the VBS itself has to use a delay (to be sure Excel is closed), then it can delete the key and reopen Excel.

Option Explicit

 Const TestAddIn = "C:\atest.xla"  'change with your add in

 Sub CreateAddIn()
   Dim W As Workbook
   Set W = Workbooks.Add
   W.IsAddin = True
   W.SaveAs TestAddIn, xlAddIn
 End Sub

 Sub LoadAddIn()
   AddIns.Add TestAddIn, False
   AddIns("atest").Installed = True
 End Sub

 Sub RemoveAddIn()
   Dim fso As FileSystemObject
   Dim ts As TextStream
   Dim Script As String, ScriptFile As String
   Dim A As AddIn
   Dim objShell
   'Access the addin to remove
   Set A = AddIns("atest")
   A.Installed = False

 Script = _
 "On Error Resume Next" & vbCrLf & _
 "'Wait until Excel is closed" & vbCrLf & _
 "WScript.Sleep 1000" & vbCrLf & _
 "'Here is the place where Excel stores the AddIns list" & vbCrLf & _
 "RegPath = ""Software\Microsoft\Office\[Version]\Excel\Add-in Manager""" & vbCrLf & _
 "'Delete the addin from the list" & vbCrLf & _
 "Set oReg = GetObject(""winmgmts:{impersonationLevel=impersonate}!"" & _" & vbCrLf & _
 """\\.\root\default:StdRegProv"")" & vbCrLf & _
 "oReg.DeleteValue &H80000001, RegPath, ""[AddIn]""" & vbCrLf & _
 "'Restart Excel" & vbCrLf & _
 "Set objShell = CreateObject(""Wscript.Shell"")" & vbCrLf & _
 "objShell.Run ""excel.exe""" & vbCrLf & _
 "'Delete this script" & vbCrLf & _
 "Set fso = CreateObject(""Scripting.FileSystemObject"")" & vbCrLf & _
 "fso.DeleteFile Wscript.ScriptFullName"

   Script = Replace(Script, "[Version]", Application.Version)
   Script = Replace(Script, "[AddIn]", A.FullName)

   'Create the VBScript
   Set fso = CreateObject("Scripting.FileSystemObject")
   ScriptFile = Replace(fso.GetTempName, ".tmp", ".vbs")
   ScriptFile = fso.BuildPath(Environ$("temp"), ScriptFile)
   Set ts = fso.CreateTextFile(ScriptFile)
   ts.Write Script
   'Run it and close Excel
   Set objShell = CreateObject("Wscript.Shell")
   objShell.Run ScriptFile
   Application.DisplayAlerts = False
 End Sub

Open in new window

valid recommendations provided by experts
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Creating Active Directory Users from a Text File

If your organization has a need to mass-create AD user accounts, watch this video to see how its done without the need for scripting or other unnecessary complexities.

  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now