Chapter 11

Automatic Procedures and Events

In This Chapter

arrow Knowing the event types that can trigger an execution

arrow Finding out where to place your event-handler VBA code

arrow Executing a macro when a workbook is opened or closed

arrow Executing a macro when a workbook or worksheet is activated

You have a number of ways to execute a VBA Sub procedure. One way is to arrange for the Sub to be executed automatically. In this chapter, I cover the ins and outs of this potentially useful feature, explaining how to set things up so that a macro is executed automatically when a particular event occurs. (No, this chapter is not about capital punishment.)

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 recognize:

check.png A workbook is opened or closed.

A window is activated or deactivated.

A worksheet is activated or deactivated.

Data is entered into ...

Get Excel VBA Programming For Dummies, 3rd Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.