disable excel add-in

Posted on 2016-10-25
Last Modified: 2016-11-15
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!
Question by:Daniel Brassard
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
LVL 18

Accepted Solution

xtermie earned 500 total points (awarded by participants)
ID: 41859891
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.
LVL 18

Assisted Solution

xtermie earned 500 total points (awarded by participants)
ID: 41859895
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

LVL 18

Expert Comment

ID: 41887604
valid recommendations provided by experts

Featured Post

Best Practices: Disaster Recovery Testing

Besides backup, any IT division should have a disaster recovery plan. You will find a few tips below relating to the development of such a plan and to what issues one should pay special attention in the course of backup planning.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Windows 10 came with  a lot of built in applications, Some organisations leave them there, some will control them using GPO's. This Article is useful for those who do not want to have any applications in their image (example:me).
The Nano Server Image Builder helps you create a custom Nano Server image and bootable USB media with the aid of a graphical interface. Based on the inputs you provide, it generates images for deployment and creates reusable PowerShell scripts that …
The viewer will learn how to use a discrete random variable to simulate the return on an investment over a period of years, create a Monte Carlo simulation using the discrete random variable, and create a graph to represent the possible returns over…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…

691 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question