Disabling COM addin with VBA

petereddy

New Member
Joined
Feb 6, 2014
Messages
43
Hi,

Is there a way, using VBA, to check whether a COM addin is active in Excel, and if it is, to deactivate it? Thanks.

Peter
 

Excel Facts

Workdays for a market open Mon, Wed, Friday?
Yes! Use "0101011" for the weekend argument in NETWORKDAYS.INTL or WORKDAY.INTL. The 7 digits start on Monday. 1 means it is a weekend.
Hi,
Try this:
VBA Code:
Sub DisableComAddIns()
  Dim objComAddIn As COMAddIn
  For Each objComAddIn In Application.COMAddIns
    If objComAddIn.Connect Then objComAddIn.Connect = False
  Next
End Sub
 
Upvote 0
Hi ZVI,

Thanks for responding. This solution appears to attempt to uninstall the addins, where I only want to untick them and leave them in my list. One of the motivations for not wanting to uninstall the addin is that my group policy won't allow it.

Any thoughts on how to do this? Thanks.

Peter
 
Upvote 0
Peter, code does not uninstall COM Add-Ins, but tries to untick (disconnect) them without deleting from the list.

If COM Add-In was registered in the HKEY_CURRENT_USER part of the computer registry, then it can be disconnected via code for the current user.
Changes are applied to the current and new sessions of Excel.

But if COM Add-In was registered with administrative privileges in the HKEY_LOCAL_USER part of the registry, then it is installed for all users of the computer (current, admin ...).
In this case user without administrative privileges can only untick it manually for current excel session.
But code faults with error message: “This add-in is installed for all users on this computer and can only be connected or disconnected by an administrator”.

If user has administrative privileges then code works for the current session of Excel.
In fact, administrative privileges allow user code to modify the registry in the HKEY_LOCAL_USER part too for applying changes to new Excel sessions.
 
Upvote 0
"
In this case user without administrative privileges can only untick it manually for current excel session.
"

I'm disappointed to hear that, but am happy to learn it. Thanks.
 
Upvote 0
The registry path for the addin is something like Computer\HKEY_CURRENT_USER\Software\Microsoft\Office\Excel\Addins\MyAddin and I'm able to change the value of the LoadBehavior value.

I know this script would be run outside Excel, but it's still related to Excel, so perhaps it's still relevant to this forum. Is there a VB script that could check the LoadBehavior
value
for this addin, and if it's not zero, set it to zero?

Thanks.
 
Upvote 0
You may play with this VBA code:
VBA Code:
Sub DisableComAddIns()
  Dim objComAddIn As COMAddIn, sRegKey As String, IsReloadMsg As Boolean
  On Error Resume Next
  With CreateObject("WScript.Shell")
    For Each objComAddIn In Application.COMAddIns
      If objComAddIn.Connect Then
        sRegKey = "HKEY_CURRENT_USER\Software\Microsoft\Office\Excel\AddIns\" & objComAddIn.progID & "\LoadBehavior"
        Err.Clear
        objComAddIn.Connect = False
        If Err Then
          IsReloadMsg = True
          .RegWrite sRegKey, 2, "REG_DWORD"
        End If
      End If
    Next
  End With
  If IsReloadMsg Then
    MsgBox "Reload Excel to apply COM Add-Ins disconnecting"
  Else
    MsgBox "COM Add-Ins have been disconnected"
  End If
End Sub
 
Upvote 0
Upvote 0
You are welcome Peter. Even if there is no good solution, we are now closer to understanding that it is a fact ...
 
Upvote 0

Forum statistics

Threads
1,214,985
Messages
6,122,606
Members
449,089
Latest member
Motoracer88

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top