Application Events

Table 11-4 shows the Application-level events. These events apply to all objects in the currently running instance of Excel.

Table 11-4. Application Events

Event name

Description

NewWorkbook

Occurs when a new workbook is created.

SheetActivate

Occurs when any sheet is activated.

SheetBeforeDoubleClick

Occurs when any worksheet is double-clicked, before the default double-click action.

SheetBeforeRightClick

Occurs when any worksheet is right-clicked, before the default right-click action.

SheetCalculate

Occurs after any worksheet is recalculated or after any changed data is plotted on a chart.

SheetChange

Occurs when cells in any worksheet are changed by the user or by an external link.

SheetPivotTableUpdate (Excel 10 only)

Occurs after the sheet containing the PivotTable report has been updated.

SheetDeactivate

Occurs when any sheet is deactivated.

SheetSelectionChange

Occurs when the selection changes on any worksheet (does not occur if the selection is on a chart sheet).

WindowActivate

Occurs when any workbook window is activated.

WindowDeactivate

Occurs when any workbook window is deactivated.

WindowResize

Occurs when any workbook window is resized.

WorkbookActivate

Occurs when any workbook is activated.

WorkbookAddinInstall

Occurs when a workbook is installed as an add-in.

WorkbookAddinUninstall

Occurs when any add-in workbook is uninstalled.

WorkbookBeforeClose

Occurs immediately before any open workbook closes.

WorkbookBeforePrint

Occurs before any open workbook is printed.

WorkbookBeforeSave

Occurs before any open workbook is saved.

WorkbookDeactivate

Occurs when any open workbook is deactivated.

WorkbookNewSheet

Occurs when a new sheet is created in any open workbook.

WorkbookOpen

Occurs when a workbook is opened.

WorkbookPivotTableCloseConnection (Excel 10 only)

Occurs after a PivotTable report connection has been closed.

WorkbookPivotTableOpenConnection (Excel 10 only)

Occurs after a PivotTable report connection has been opened.

Unfortunately, Excel makes it a bit more difficult to reach the Application events than events in the other categories. Here is a step-by-step procedure for reaching the event code shells for the Application events:

1. Use the VBA Insert menu to insert a class module into your project. Let us call this class module CApp (short for Class Application). In the declaration section of the class module, add the line:

Public WithEvents App As Application

Choosing the App object in the objects drop-down should now give you access to the Application event code shells, as shown in Figure 11-2.

0 0

Post a comment