Where Does the VBA Code Go

It's very important to understand where your event-handler procedures go. They must reside in the Code window of an Object module. They simply won't work if you put them in a standard VBA module.

Figure 11-1 shows the VBE window with one project displayed in the Project window. (Refer to Chapter 3 for some background on the VBE.) Notice that the project consists of several objects:

^ One object for each worksheet in the workbook (in this case, three Sheet objects)

^ An object labeled ThisWorkbook

^ A VBA module that I inserted manually using the InsertOModule command

Figure 11-1:

The VBE window displays items for a single project.

Figure 11-1:

The VBE window displays items for a single project.

Double-clicking any of these objects displays the code associated with the item, if any.

The event-handler procedures that you write go into the Code window for the ThisWorkbook item (for workbook-related events) or one of the Sheet objects (for worksheet-related events).

0 0

Post a comment