Microsoft Office Tutorials and References
In Depth Information
3.1.2.1 The ThisWorkbook object
Under the Forms node, there is a node for each form in the project. Forms are also called
UserForms or custom dialog boxes. We will discuss UserForms later in this chapter.
Under the Modules node, there is a node for each code module in the project. Code modules are
also called standard modules. We will discuss modules later in this chapter.
Under the Classes node, there is a node for each class module in the project. We will discuss
classes later in this chapter.
The main purpose of the Project Explorer is to allow us to navigate around the project.
Worksheets and UserForms have two components—a visible component (a worksheet or dialog)
and a code component. By right-clicking on a worksheet or UserForm node, we can choose to
view the object itself or the code component for that object. Standard modules and class modules
have only a code component, which we can view by double-clicking on the corresponding node.
Let us take a closer look at the various components of an Excel project.
3.1.2.1 The ThisWorkbook object
Under each node in the Project Explorer labeled Microsoft Excel Objects is a node labeled
ThisWorkbook. This node represents the project's workbook, along with the code component (also
called a code module) that stores event code for the workbook. (We can also place independent
procedures in the code component of a workbook module, but these are generally placed in a
standard module, discussed later in this chapter.)
Simply put, the purpose of events is to allow the VBA programmer to write code that will execute
whenever one of these events fires. Excel recognizes 19 events related to workbooks. We will
discuss these events in Chapter 11 ; you can take a quick peek at this chapter now if you are
curious. Some examples:
The Open event, which occurs when the workbook is opened.
The BeforeClose event, which occurs just before the workbook is closed.
The NewSheet event, which occurs when a new worksheet is added to the workbook.
The BeforePrint event, which occurs just before the workbook or anything in it is printed.
3.1.2.2 Sheet objects
Under each Microsoft Excel Objects node in the Project Explorer is a node for each sheet. (A
sheet is a worksheet or a chartsheet.) Each sheet node represents a worksheet or chartsheet's
visible component, along with the code component (also called a code module) that stores event
code for the sheet. We can also place independent procedures in the code component of a sheet
module, but these are generally placed in a standard module, discussed next.
Excel recognizes 7 events related to worksheets and 13 events related to chartsheets. We will
discuss these events in Chapter 11 .
3.1.2.3 Standard modules
A module , also more clearly referred to as a standard module , is a code module that contains
general procedures (functions and subroutines). These procedures may be macros designed to be
run by the user, or they may be support programs used by other programs. (Remember our
discussion of modular programming.)
3.1.2.4 Class modules
Search JabSto ::




Custom Search