Excel 2019

Application WorkbookAddinInstall and WorkbookAddinUninstall Events

In this tutorial, you'll learn about the application events WorkbookAddinInstall and WorkbookAddinUninstall. These events occur when you install a workbook as an add-in or uninstall an add-in. Before writing code for these events, open VBE (Alt+F11) and write the following code in ThisWorkbook code module (for details, visit how to capture application events:

Option Explicit

Public WithEvents App As Application

Private Sub Workbook_Open()
 Set App = Application
End Sub

WorkbookAddinInstall

Syntax: App_WorkbookAddinInstall(Wb)

The WorkbookAddinInstall event occurs when you install a workbook as an add-in. See how to create and install an add-in. The App_WorkbookAddininstall procedure has one argument Wb which represents the installed workbook.

App_WorkbookAddinInstall Example:

Option Explicit
Public WithEvents App As Application

Private Sub App_WorkbookAddinInstall(ByVal Wb As Workbook)
 MsgBox Wb.Name & " has been installed as an add-in"
End Sub

Private Sub Workbook_Open()
 Set App = Application
End Sub

The WorkbookAddinInstall is an application-level event that affects all open workbooks in an Excel session. To work with a particular workbook use the Workbook_AddinInstall procedure.

WorkbookAddinUninstall

Syntax: App_WorkbookAddinUninstall(Wb)

The WorkbookAddinUninstall event occurs when any add-in workbook is uninstalled. The App_WorkbookAddinUninstall procedure has one argument Wb which represents the uninstalled workbook.

App_WorkbookAddinUninstall Example:

Option Explicit
Public WithEvents App As Application

Private Sub App_WorkbookAddinUninstall(ByVal Wb As Workbook)
 MsgBox Wb.Name & " has been uninstalled"
End Sub

Private Sub Workbook_Open()
 Set App = Application
End Sub

The WorkbookAddinUninstall is an application-level event that affects all open workbooks in an Excel session. To work with a particular workbook use the Workbook_AddinUninstall procedure.

Advertisement:
Advertisement: