O'Reilly logo

Excel VBA Programming For Dummies, 5th Edition by John Walkenbach, Michael Alexander

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 11

Automatic Procedures and Events

IN THIS CHAPTER

Bullet Knowing the event types that can trigger an execution

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

Bullet Executing a macro when a workbook is opened or closed

Bullet 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, you explore 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

An event is basically something that happens Excel. Following are a few examples of the types of events that Excel can recognize:

  • A workbook is opened or closed.
  • A window is activated or deactivated.
  • A worksheet is activated or deactivated.
  • Data is entered into a cell or the cell is edited.
  • A workbook is saved.
  • An object, such as a button, is clicked.
  • A particular key or key combination is pressed.
  • A particular time ...

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