[VBA] How to Disable (Uninstall) an Excel Add-in Using a Macro

If you distribute specific tools as Excel Add-ins, it is very user-friendly to provide a feature that allows users to temporarily turn off the functionality or easily disable it when it is no longer needed. Asking users to manually open “Excel Options” and uncheck the add-in can be cumbersome.

Using VBA, you can automate the process of “disabling a specific currently active add-in with a single button press.” This article introduces safe and reliable VBA code to locate an installed add-in by name and unregister (disable) it.

目次

VBA Sample Code to Disable an Add-in

This macro operates in the following steps:

  1. Searches for an add-in with the specified name from the list of add-ins installed in Excel.
  2. If the add-in is found, it sets its .Installed property to False to disable it.
  3. If the add-in is not found, it notifies the user via a message box.

Complete Code

' Disable (Uninstall) the add-in with the specified name
Sub UninstallMyToolAddin()

    ' == Define Constants and Variables ==
    ' The Title of the target add-in (as shown in the Add-ins dialog)
    Const ADDIN_TITLE As String = "My Tool Box" 
    Dim targetAddin As AddIn
    
    ' == Search if the specified add-in is installed ==
    On Error Resume Next ' Prevent error if the add-in is not found
    Set targetAddin = Application.AddIns(ADDIN_TITLE)
    On Error GoTo 0 ' Restore normal error handling
    
    ' == Check existence and branch processing ==
    If targetAddin Is Nothing Then
        ' If the add-in was not found
        MsgBox "'" & ADDIN_TITLE & "' is not installed.", vbExclamation
    Else
        ' If the add-in was found
        If targetAddin.Installed = False Then
            MsgBox "'" & ADDIN_TITLE & "' is already disabled.", vbInformation
        Else
            ' Disable the add-in (Uncheck the box)
            targetAddin.Installed = False
            MsgBox "'" & ADDIN_TITLE & "' has been disabled.", vbInformation
        End If
    End If

End Sub

Explanation of the Code

Const ADDIN_TITLE As String = "My Tool Box"

This declares the “Title” of the add-in you want to disable as a constant. Note: The Title may differ from the add-in’s filename (e.g., MyToolBox.xlam). You must specify the exact name that appears in the “Add-ins” dialog box list.

On Error Resume Next

The code Application.AddIns(ADDIN_TITLE) will throw an error if an add-in with the specified name is not currently installed in Excel. Including this line ensures that the macro does not crash upon error but proceeds to the next line.

Set targetAddin = Application.AddIns(ADDIN_TITLE)

This attempts to find the add-in object matching ADDIN_TITLE from the Application.AddIns collection and store it in the targetAddin variable.

If targetAddin Is Nothing Then

If the add-in was not found (due to the On Error Resume Next allowing the code to pass), the targetAddin variable will remain empty (Nothing). This If statement checks the variable to determine if the add-in exists and branches the logic accordingly.

targetAddin.Installed = False

This is the core command to disable the add-in. Setting the .Installed property of the add-in object to False effectively unchecks the box in the “Add-ins” dialog, making the add-in’s features unavailable.

Summary

In this article, we explained how to disable an installed add-in using VBA.

  1. Access a specific add-in using Application.AddIns("Add-in Title").
  2. Use On Error Resume Next to handle cases where the add-in does not exist.
  3. Disable the add-in using the property .Installed = False.

By preparing this “Uninstaller” macro alongside your add-in’s installer, you empower users to manage their add-ins easily, resulting in a more polished and user-friendly tool.

よかったらシェアしてね!
  • URLをコピーしました!
  • URLをコピーしました!

この記事を書いた人

私が勉強したこと、実践したこと、してることを書いているブログです。
主に資産運用について書いていたのですが、
最近はプログラミングに興味があるので、今はそればっかりです。

目次