A VBA procedure that executes in response to an event is called an event-handler procedure. These are always Sub procedures (as opposed to Function procedures). Writing these event-handlers is relatively straightforward after you understand how the process works. It all boils down to a few steps, all of which I explain later:
1. Identify the event you want to trigger the procedure.
2. Press Alt+F11 to Activate the Visual Basic Editor.
3. In the VBE Project Window, double-click the appropriate object listed under Microsoft Excel Objects.
For workbook-related events, the object is ThisWorkbook. For a workbook-related event, the object is a Worksheet object (such as Sheet1).
4. In the Code window for the object, write the event-handler procedure that is executed when the event occurs.
This procedure will have a special name that identifies it as an event-handler procedure.
These steps become clearer as you progress through the chapter. Trust me.
Was this article helpful?