To open VBE press Alt + F11
(For more information, see How to open Visual Basic Editor), for writing an event-handler for the workbook, you need to click ThisWorkbook
in the Project window and then choose Workbook from the Object
drop-down, the next drop-down displays a list of all workbook events, as shown in the following figure:
- Double click
ThisWorkbook
object to open its code window - Select
Workbook
from theObject
drop-down list - The
Procedure
drop-down list shows the list of event procedures
List of Workbook Events
Activate
TheWorkbook_Activate
event procedure is executed when the workbook is activated.Deactivate
TheWorkbook_Deactivate
event procedure is executed when the workbook loses focus.AddinInstall
TheWorkbook_AddinInstall
event procedure is executed when the add-in is installed.AddinUninstall
TheWorkbook_AddinUninstall
event procedure is executed when the add-in is just uninstalled.AfterRemoteChange
TheWorkbook_AfterRemoteChange
event procedure is executed when changes are merged into the workbook by a remote user.BeforeRemoteChange
TheWorkbook_BeforeRemoteChange
event procedure is executed just before the changes are merged into the workbook by a remote user.AfterSave
TheWorkbook_AfterSave
event procedure is executed when the workbook is saved.BeforeSave
TheWorkbook_BeforeSave
event procedure is executed just before the workbook is saved. This event can be helpful to prevent Save As command.AfterXmlExport
TheWorkbook_AfterXmlExport
event procedure is executed when Excel saves or exports XML data from the workbook.AfterXmlImport
TheWorkbook_AfterXmlImport
event procedure is executed when an existing XML data connection is refreshed or new XML data is imported into the workbook.BeforeXmlExport
TheWorkbook_BeforeXmlExport
event procedure is executed just before the Excel saves or exports XML data from the workbook.BeforeXmlImport
TheWorkbook_BeforeXmlImport
event procedure is executed before XML data connection is refreshed or before new XML data is imported into the workbookBeforeClose
TheWorkbook_BeforeClose
event procedure is executed just before the workbook closes.Open
TheWorkbook_Open
event is executed when the workbook opens.BeforePrint
TheWorkbook_BeforePrint
event procedure is executed before a user attempts to print any portion of the workbook.ModelChange
TheWorkbook_ModelChange
event procedure is executed when a user changes the Data Model (for example, columns added or deleted).NewChart
TheWorkbook_NewChart
event procedure is executed when a new chart is added to the workbook.NewSheet
TheWorkbook_NewSheet
event procedure is executed when a new worksheet is added to the workbook.SheetActivate
TheWorkbook_SheetActivate
event procedure is executed when a worksheet is activated in the workbook.SheetDeactivate
TheWorkbook_SheetDeactivate
event procedure is executed when a worksheet loses focus, such as when a different sheet in the workbook is activated.SheetBeforeDelete
TheWorkbook_SheetBeforeDelete
event procedure is executed before any worksheet in the workbook is deleted.SheetBeforeDoubleClick
TheWorkbook_SheetBeforeDoubleClick
event procedure is executed when a cell on any worksheet is about to be double-clicked.SheetBeforeRightClick
TheWorkbook_SheetBeforeRightClick
event procedure is executed when a cell on any worksheet is about to be right-clicked.SheetCalculate
TheWorkbook_SheetCalculate
event procedure is executed when a user recalculates any worksheet.SheetChange
TheWorkbook_SheetChange
event procedure is executed when any cell’s contents are changed on any worksheet in the workbook.SheetSelectionChange
TheWorkbook_SheetSelectionChange
event procedure is executed when a different cell is selected on any worksheet in the workbook.SheetFollowHyperlink
TheWorkbook_SheetFollowHyperlink
event procedure is executed when a user click any hyperlink on any worksheet in the workbook.SheetLensGalleryRenderComplete
TheWorkbook_SheetLensGalleryRenderComplete
event procedure is executed when a user selects the Quick Analysis tool.SheetTableUpdate
TheWorkbook_SheetTableUpdate
event procedure is executed when the user changes a table object.RowsetComplete
TheWorkbook_RowsetComplete
event procedure is executed when a user either drills through the recordset or invokes the rowset action on an OLAP PivotTable.PivotTableCloseConnection
TheWorkbook_PivotTableCloseConnection
event procedure is executed when a pivot table closed the connection to its data source.PivotTableOpenConnection
TheWorkbook_PivotTableOpenConnection
event procedure is executed when a PivotTable report opens the connection to its data source.SheetPivotTableAfterValueChange
TheWorkbook_SheetPivotTableAfterValueChange
event procedure is executed when a cell or range of cells that contain formulas inside a PivotTable are edited or recalculated.SheetPivotTableBeforeAllocateChanges
TheWorkbook_SheetPivotTableBeforeAllocateChanges
event procedure is executed before changes are applied to a PivotTable.SheetPivotTableBeforeCommitChanges
TheWorkbook_SheetPivotTableBeforeCommitChanges
event procedure is executed before changes are committed against the OLAP data source for a PivotTable.SheetPivotTableBeforeDiscardChanges
TheWorkbook_SheetPivotTableBeforeDiscardChanges
event procedure is executed before changes to a PivotTable are discarded.SheetPivotTableChangeSync
TheWorkbook_SheetPivotTableChangeSync
event procedure executed after a user changes a pivot table.SheetPivotTableUpdate
TheWorkbook_SheetPivotTableUpdate
event procedure executed when any worksheet get updated in the workbook that hold pivot tables.Sync
TheWorkbook_Sync
(deprecated, you should not use it) procedure is executed when a user synchronizes the local copy of a sheet in a workbook that is part of aDocument Workspace
with the copy on the server.WindowActivate
TheWorkbook_WindowActivate
event procedure is executed when user shifts the focus to any window showing the workbook.WindowDeactivate
TheWorkbook_WindowDeactivate
event procedure is executed when the user shifts the focus away from any window showing the workbook.WindowResize
TheWorkbook_WindowResize
event procedure is executed when a user opens, resizes, maximizes, or minimizes any window showing the workbook.