Excel 2010 Bible

(National Geographic (Little) Kids) #1

Part VI: Programming Excel with VBA


876


TABLE 43.1

Workbook Events


Event Action That Triggers the Event
Activate The workbook is activated.
AddinInstall The workbook is installed as an add-in.
AddinUninstall The workbook is uninstalled as an add-in.
BeforeClose The workbook is about to be closed.
BeforePrint The workbook (or anything in it) is about to be printed.
BeforeSave The workbook is about to be saved.
Deactivate The workbook is deactivated.
NewSheet A new sheet is created in the workbook.
Open The workbook is opened.
SheetActivate Any sheet in the workbook is activated.
SheetBeforeDoubleClick Any worksheet in the workbook is double-clicked. This event occurs
before the default double-click action.
SheetBeforeRightClick Any worksheet in the workbook is right-clicked. This event occurs
before the default right-click action.
SheetCalculate Any worksheet in the workbook is calculated (or recalculated).
SheetChange Any worksheet in the workbook is changed by the user.
SheetDeactivate Any sheet in the workbook is deactivated.
SheetFollowHyperlink Any hyperlink in the workbook is clicked.
SheetSelectionChange The selection on any worksheet in the workbook is changed.
WindowActivate Any window of the workbook is activated.
WindowDeactivate Any workbook window is deactivated.
WindowResize Any workbook window is resized.

The remainder of this section presents examples of using workbook-level events. All the example
procedures that follow must be located in the code module for the ThisWorkbook object. If you
put them into any other type of code module, they will not work.

Using the Open event

One of the most common monitored events is a workbook’s Open event. This event is triggered
when the workbook (or add-in) opens and executes the Workbook_Open procedure. A
Workbook_Open procedure is very versatile and is often used for the following tasks:
Free download pdf