O'Reilly logo

Excel® 2007 VBA Programmer's Reference by Michael Alexander, Rob Bovey, Stephen Bullen, John Green

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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.

Note

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 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required