Event procedures

We have seen examples of events in this chapter. For example, the Click event that is activated when a Command button is clicked. Other events occur in Excel, for example, when a workbook is opened, or when a new worksheet is created, or when a chart is printed. The VBA programmer can write code that activates whenever an Excel event of the type just described occur. This code is placed in an event procedure. There are many event procedures that can be used - too many for coverage in this book, and therefore we will look only at a couple of examples here. Appendix 2 shows a list of event procedures for each object. There are, excluding control events discussed earlier, four objects in Excel that can contain events. They are:

Not all events are defined by all objects. In general, however, if an object has an event, its parent object will also have the same event. For example, the Change event is contained at the lowest level by the worksheet object, and its parent (the workbook object) also has this event, called Workbook_SheetSelectionChange. In turn, the workbook object's parent, the application, also has a Change event. (Application-level events work slightly differently than other events.)

Note also that Chart events only apply to Chart sheets, and not to Chart objects embedded in sheets.

0 -1

Post a comment