In This Chapter
- Recognizing the types of events that Excel can monitor
- Figuring out what you need to know to work with events
- Exploring examples of Workbook events, and Worksheet events
- Using Application events to monitor all open workbooks
- Seeing examples of processing time-based events and keystroke events
What You Should Know about Events
In many of the example macros in this book, there will be code implemented as event procedures, which are procedures that automatically trigger upon the occurrence of an event. An event is nothing more than an action that takes place during a session in Excel.
Everything that happens in Excel happens to an object through an event. A few examples of events are opening a workbook, adding a worksheet, changing a value in a cell, saving a workbook, double-clicking a cell, and the list goes on. The nifty thing is that you can tell Excel to run a certain macro or piece of code when a particular event occurs.
Excel is programmed to monitor many different events. These events can be classified as:
- Workbook events: Events that occur for a particular workbook. Examples of such events include Open (the workbook is opened or created), BeforeSave (the workbook is about to be saved), and NewSheet (a new sheet is added).
- Worksheet events: Events that occur for a particular worksheet. Examples include Change (a cell on the sheet is changed), SelectionChange (the user moves the cell indicator), and Calculate (the worksheet ...