Microsoft Office Tutorials and References
In Depth Information
Getting Acquainted with Workbook-Level Events
Action That Triggers the Event
A workbook is deactivated.
A chart has been created.
A new sheet is created in a workbook.
A workbook is opened.
Any sheet is activated.
Any worksheet is double-clicked. This event occurs before the default
Any worksheet is right-clicked. This event occurs before the default
Any worksheet is calculated (or recalculated).
Any worksheet is changed by the user or by an external link.
Any sheet is deactivated.
A hyperlink on a sheet is clicked.
A pivot table is changed or refreshed.
The selection on any worksheet is changed.
Any workbook window is activated.
Any workbook window is deactivated.
Any workbook window is resized.
If you need to monitor events for any workbook, you need to work with Application -
level events (see “Monitoring with Application Events,” later in this chapter). 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 won’t work.
The Open event
One of the most common events that is monitored is the Open event for a workbook. This event
is triggered when the workbook (or add-in) is opened and executes the procedure named
Workbook_Open . A Workbook_Open procedure is often used for tasks such as these:
h Displaying welcome messages.
h Opening other workbooks.
h Setting up shortcut menus.
h Activating a particular sheet or cell.
h Ensuring that certain conditions are met. For example, a workbook may require that a
particular add-in is installed.