Excel 2019

Add-ins Events

An Add-In object has two events: AddInInstall (occurs when the add-in is installed) and AddInUninstall (occurs when the add-in is uninstalled). These event are the workbook events so you must write the Workbook_AddInInstall and Workbook_AddInUninstall event-listener procedures in the ThisWorkbook code module.

Open a new Workbook, press Alt + F11 to open the Visual Basic Editor (VBE) and write event-handler procedures for AddInInstall and AddInUninstall in the ThisWorkbook code module. The following example is displayed a message when the add-in is installed or uninstalled:

Code:

Private Sub Workbook_AddInInstall()
 MsgBox ThisWorkbook.Name & " add-in has been installed."
End Sub

Private Sub Workbook_AddinUninstall()
 MsgBox ThisWorkbook.Name & " add-in has been un-installed."
End Sub

To test the code save the workbook as an add-in (Learn how to create an add-in). Click the save button or press Ctrl + S from the VBE to open the Save As dialog box, write add-in name in File name field and select Excel Add-in (*.xlam) from the Save as type field as shown in following figure:

Workbook_AddInInstall

To test this event, open a new or existing workbook, click Developer tab and choose Excel Add-ins and install your newly created add-in (for details read Installing XLAM Add-ins):

Choose your add-in and click OK to install the add-in. After closing the Add-ins dialog box the Workbook_AddInInstall event procedure will execute which display the message BrainbBell.xlam add-in has been installed:

Workbook_AddInUninstall

Next, we’ll test the Workbook_AddInUninstall event procedure. Click Excel Add-ins from the Developer tab to display the Add-Ins dialog box and uncheck your newly created add-in and click OK. It will uninstall the add-in and close its file:

After clicking the Ok button the Workbook_AddInUninstall event procedure will execute which display the message BrainbBell.xlam add-in has been un-installed:

Advertisement:
Advertisement: