Microsoft Office Tutorials and References
In Depth Information
Chapter 19: Understanding Excel’s Events
In the Visual Basic Editor (VBE) window, each project is listed in the Projects window. The project
components are arranged in a collapsible list, as shown in Figure 19-1.
Figure 19-1: The components for each VBA project are listed in the Project window.
Each of the following components has its own code module:
h Sheet objects (for example, Sheet1, Sheet2, and so on): Use this module for
eventhandler code related to the particular worksheet.
h Chart objects (that is, chart sheets): Use this module for event-handler code related to
the chart.
h ThisWorkbook object: Use this module for event-handler code related to the workbook.
h General VBA modules: You never put event-handler procedures in a general (that is,
nonobject) module.
h UserForm objects: Use this module for event-handler code related to the UserForm or
controls on the UserForm.
h Class modules: Use class modules for special-purpose event handlers, including
application-level events and events for embedded charts.
Even though the event-handler procedure must be located in the correct module, the procedure
can call other standard procedures stored in other modules. For example, the following
eventhandler procedure, located in the module for the ThisWorkbook object, calls a procedure
named WorkbookSetup , which you can store in a regular VBA module:
Private Sub Workbook_Open()
Call WorkbookSetup
End Sub
 
Search JabSto ::




Custom Search