Preparing for the Big Event

What types of events am I talking about here? Good question. An event is basically something that happens in Excel. Following are a few examples of the types of events that Excel can deal with:

i A workbook is opened or closed. i A window is activated. i A worksheet is activated or deactivated. i Data is entered into a cell or the cell is edited. i A workbook is saved. i A worksheet is calculated. i An object, such as button, is clicked. i A particular key or key combination is pressed.

1 A cell is double-clicked. 1 A particular time of day occurs. i An error occurs.

Most Excel programmers never need to worry about most of the events in this list. You should, however, at least know that these events exist because they may come in handy someday. In this chapter, I discuss the most commonly used events. To simplify things, I talk about two types of events: workbook and worksheet.

Table 11-1 lists most of the workbook-related events. You can access the complete list if you follow these directions:

1. Choose the ThisWorkbook object in the Project window.

2. Display the Code window.

Choose ViewOCode or press F7 to do this.

3. Choose the Workbook object in the Object drop-down list (at the top-left of the Code window).

4. Expand the Procedure drop-down list (at the top-right of the Code window).

Table 11-1

Workbook Events

Event

When It's Triggered

Activate

The workbook is activated.

AddinInstall

An add-in is installed (relevant only for add-ins).

AddinUninstall

The add-in is uninstalled (relevant only for add-ins).

BeforeClose

The workbook is closed.

BeforePrint

The workbook is printed.

BeforeSave

The workbook is saved.

Deactivate

The workbook is deactivated.

NewSheet

A new sheet is added to the workbook.

Open

The workbook is opened.

SheetActivate

A sheet in the workbook is activated.

SheetBefore DoubleClick

A cell in the workbook is double-clicked.

SheetBefore RightClick

A cell in the workbook is right-clicked.

Event

When It's Triggered

SheetCalculate

A sheet in the workbook is recalculated.

SheetChange

A change is made to a cell in the workbook.

SheetDeactivate

A sheet in the workbook is deactivated.

SheetFollowHyperlink

A hyperlink in a worksheet is clicked.

SheetSelectionChange

The selection is changed.

WindowActivate

The workbook window is activated.

WindowDeactivate

The workbook window is deactivated.

WindowResize

The workbook window is resized.

Table 11-2 lists most of the worksheet events. These events are accessible if

you follow these directions:

1. Choose a Worksheet object in the Project window.

2. Display the Code window.

3. Choose the Worksheet object in the Object list (at the top of the Code

window).

4. Expand the Procedure drop-down list.

Table 11-2

Worksheet Events

Event

When It's Triggered

Activate

The worksheet is activated.

BeforeDoubleClick

A cell in the worksheet is double-clicked.

BeforeRightClick

A cell in the worksheet is right-clicked.

Calculate

The worksheet is recalculated.

Change

A change is made to a cell in the worksheet.

Deactivate

The worksheet is deactivated.

FollowHyperlink

A hyperlink is activated.

SelectionChange

The selection is changed.

Was this article helpful?

0 0

Post a comment