O'Reilly logo

Excel® VBA: 24-Hour Trainer by Tom Urtis

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 12. Automating Procedures with Workbook Events

In Lesson 11, you learned about worksheet-level events and how they are triggered by actions relating to individual worksheets. Workbooks themselves can also recognize and respond to a number of events that take place at the workbook level. This lesson describes how you can further customize your workbooks with VBA procedures for the most commonly used workbook events.

WORKBOOK EVENTS — AN OVERVIEW

Workbook events occur within a particular workbook. Many workbook events occur because something happened to an object in the workbook, such as a worksheet — any worksheet — that was activated, or a cell — any cell — that was changed. Other workbook events occur because the workbook was imposed upon to do something, such as to open or close, or to be saved or printed.

Note

Unless the VBA code itself purposely refers to other workbooks, event procedures at the workbook level affect only the workbook within which the code resides.

Where Does the Workbook Event Code Go?

You saw in Lesson 11 that each individual worksheet has its own module. Workbooks are similar to worksheets in this respect, because a workbook is also an Excel object, and has its own module already present and accounted for when the workbook is created.

Note

Workbook-level event code always goes into the workbook module. You never need to create a workbook module or a worksheet module; Excel creates those modules automatically with every new workbook. If a workbook-level event ...

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