In This Chapter
This chapter explains the concept of Excel events, and I include many examples that you can adapt to your own needs. As you will see, understanding events can give your Excel applications a powerful edge. Here, you will find:
An overview of the types of events that Excel can monitor
Essential background information for working with events
Chart events, and
Application events to monitor all open workbooks
Examples of processing time-based events and keystroke events
In several earlier chapters in this book, I present examples of VBA event handler procedures, which are specially named procedures that are executed when a specific event occurs. A simple example is the
CommandButton1_Click procedure that is executed when the user clicks an object named
CommandButton1 stored on a UserForm or on a worksheet.
Excel is capable of monitoring a wide variety of events and executing your VBA code when a particular event occurs. Following are just a few examples of the types of events that Excel recognizes:
A workbook is opened or closed.
A window is activated.
A worksheet is activated or deactivated.
Data is entered into a cell or the cell is edited.
A workbook is about to be saved.
A workbook is about to be printed.
A worksheet is calculated.
An object is clicked.
The data in a chart is updated.
A particular key or key combination is pressed.
A particular time of day occurs.