Excel 2019 Bible

(singke) #1

Part VI: Automating Excel


TA B L E 4 6 .1 Workbook Events

Event Action That Triggers the Event
Activate The workbook is activated.
AfterSave The workbook was saved.
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.
SheetChange Any worksheet in the workbook is changed by the
user.
SheetDeactivate Any sheet in the workbook is deactivated.
SheetSelectionChange The selection on any worksheet in the workbook is
changed.
WindowActivate Any workbook window is activated.
WindowDeactivate Any workbook window is deactivated.

The remainder of this section presents examples of using workbook-level events.

All the sample 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 won’t work—and you will not see an error message.

Using the Open event
One of the most common monitored events is a workbook’s Open event. This event is
triggered when the workbook opens and executes the Workbook_Open procedure. A
Workbook_Open procedure is versatile, and it is often used for the following tasks:

■ (^) Displaying welcome messages
■ Opening other workbooks

Free download pdf