Microsoft Office Tutorials and References
In Depth Information
Executing Sub Procedures
Figure 9-4: Assigning a macro to a button.
Executing a procedure when an event occurs
You might want a procedure to execute when a particular event occurs. Examples of events
include opening a workbook, entering data into a worksheet, saving a workbook, clicking a
CommandButton ActiveX control, and many others. A procedure that is executed when an event
occurs is an event handler procedure. Event handler procedures are characterized by the following:
h They have special names that are made up of an object, an underscore, and the event
name. For example, the procedure that is executed when a workbook is opened is
Workbook_Open .
h They’re stored in the Code module for the particular object.
Chapter 19 is devoted to event handler procedures.
Executing a procedure from the Immediate window
You also can execute a procedure by entering its name in the Immediate window of the VBE. If
the Immediate window isn’t visible, press Ctrl+G. The Immediate window executes VBA
statements while you enter them. To execute a procedure, simply enter the name of the procedure in
the Immediate window and press Enter.
Search JabSto ::

Custom Search