30.04.2017 Views

4523756273

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Chapter 11<br />

Automatic Procedures and Events<br />

In This Chapter<br />

▶ Knowing the event types that can trigger an execution<br />

▶ Finding out where to place your event-handler VBA code<br />

▶ Executing a macro when a workbook is opened or closed<br />

▶ Executing a macro when a workbook or worksheet is activated<br />

You have a number of ways to execute a VBA Sub procedure. One way is<br />

to arrange for the Sub to be executed automatically. In this chapter, I<br />

cover the ins and outs of this potentially useful feature, explaining how to set<br />

things up so that a macro is executed automatically when a particular event<br />

occurs. (No, this chapter is not about capital punishment.)<br />

Preparing for the Big Event<br />

What types of events am I talking about here? Good question. An event is<br />

basically something that happens in Excel. Following are a few examples of<br />

the types of events that Excel can deal with:<br />

✓ A workbook is opened or closed.<br />

✓ A window is activated.<br />

✓ A worksheet is activated or deactivated.<br />

✓ Data is entered into a cell or the cell is edited.<br />

✓ A workbook is saved.<br />

✓ A worksheet is calculated.<br />

✓ An object, such as a button, is clicked.<br />

✓ A particular key or key combination is pressed.<br />

✓ A particular time of day occurs.<br />

✓ An error occurs.

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!