Page 312 - Excel Workbook for Dummies
P. 312
33_798452 ch23.qxp 3/13/06 7:51 PM Page 295
Chapter 23: Using the Visual Basic Editor 295
Run Sub/User Form
View Microsoft Excel Exit Design Mode
Figure 23-3: Insert UserForm Properties
The buttons Save Copy Break Microsoft Visual Basic Help
on the
Standard
toolbar in
the Visual
Basic Editor Cut Redo Toolbox window
window.
Paste Undo Reset Object Browser
Find Project Explorer
The two most important windows (at least, when you’re first starting out using
the Visual Basic Editor) are the Project Explorer and the Code window. The Project
Explorer window to the immediate left of the Code window (refer to Figure 23-2)
shows you all the projects you have open in the Visual Basic Editor and enables you
to easily navigate their various parts. Note that in VBA, a project consists of all the
code and user forms that belong to a particular workbook along with the sheets of
the workbook itself.
Editing a recorded macro
The macros that you record in the workbook as well as any you write for it in the
Visual Basic Editor are recorded on module sheets to which Excel assigns generic
names such as Module1, Module2, and so forth. The actual lines of VBA programming
code for the macro stored on a particular module sheet appears in the Code window
when you select its module in the Project Explorer (the Code window appears to the
immediate right of the Project Explorer).
If you want to rename a module in your VBA project to something a little more
descriptive than Module1, Module2, and so on, you can do this in the Properties
window that appears immediately below the Project Explorer. Simply click the
name (such as Module1) that appears after the label, (Name), on the Alphabetic
tab in the Properties window and replace it with a more descriptive name before you
press Enter. When renaming a module, remember that you must use the same naming
guidelines as when naming a range name in a worksheet: Begin the module name with
a letter, not a symbol or number, and don’t put any spaces between words (use under-
lines instead).
After you’ve created a macro, you don’t necessarily have to rerecord it to change the
way it behaves. In many cases, you may find it more expedient to change its behavior
by simply editing its contents in the Visual Basic Editor. Note that if the macro you
want to edit is stored in your Personal Macro Workbook (that PERSONAL.XLS file in
the XLSTART folder), it’s much easier to edit the macro in the Visual Basic Editor by
first unhiding the Personal Macro Workbook file in Excel.
Keep in mind that Excel automatically hides the Personal Macro Workbook when you
exit Excel. This means that you must use the Windows➪Unhide command to make
the PERSONAL.XLS workbook visible if you want to edit its macros directly from this
workbook file.