Chapter 9. Event Procedures

Excel makes it very easy for you to write code that runs when a range of worksheet, chart sheet, and workbook events occur. Previous chapters have shown you how to highlight the active row and column of a worksheet by placing code in the Worksheet_SelectionChange event procedure (see Chapter 1). This runs every time the user selects a new range of cells. You have also seen how to synchronize the worksheets in a workbook using the Worksheet_Deactivate and Worksheet_Activate events (see Chapter 3).

It is easy to create workbook, chart sheet, and worksheet events, because Excel automatically provides you with code modules for these objects. However, note that the chart events that are supplied automatically in a chart module apply only to chart sheets, not to embedded charts. If you want to write event procedures for embedded charts, you can do so, but it takes a bit more knowledge and effort.

Many other high-level events also can be accessed, for the Application object, for example. These events are covered later on in Chapters 16 and 26. Events associated with controls and forms are also discussed in their own chapters. This chapter examines in more detail worksheet, chart, and workbook events and related issues.


Event procedures are always associated with a particular object and are contained in the class module that is associated with that object, such as the ThisWorkbook module or the code module behind a worksheet or a UserForm. Don't try to place ...

Get Excel® 2007 VBA Programmer's Reference now with the O’Reilly learning platform.

O’Reilly members experience live online training, plus books, videos, and digital content from nearly 200 publishers.