Page 50 - Excel Progamming Weekend Crash Course
P. 50
d540629 ch02.qxd 9/2/03 9:27 AM Page 25
Session 2 — The VBA Code Editor 25
You can record a macro for certain actions, and examine the resulting macro to get a
feel for the VBA code that is required; then write your own code as needed.
You can record a macro and use the resulting VBA code as-is or with modifications
in your own program.
Because of these potential uses for macros, it’s worthwhile to understand how they work.
Recording a Macro
Follow these steps to record a macro.
1. From the Excel menu, select Tools ➪ Macro ➪ Record New Macro. Excel displays the
Record Macro dialog box, shown in Figure 2-6.
Figure 2-6 The Record Macro dialog box
A macro name must begin with a letter. Subsequent characters can be let-
ters, numbers, or the underscore character. Spaces and other characters are
Note not allowed.
2. In the Macro Name field, enter a descriptive name for the macro.
3. If you want to run this macro using a keyboard shortcut, enter the key in the
Shortcut Key field. For example, if you enter M, you’ll be able to run the macro by
pressing Ctrl+M. Otherwise leave this box blank.
4. Select the macro storage location from the drop-down list. Your options are:
This Workbook. The macro is stored in the current workbook.
New Workbook. The macro is stored in a new workbook. You are prompted to
name and save this new workbook when you exit Excel.
Personal Macro Workbook. The macro is stored in a personal macro workbook.
Choose this option if you want the macro available whenever you run Excel.
5. If desired, edit the text in the Description box. This text is included as a comment
(an explanatory note) in the macro code.
6. Click OK. Excel displays a small toolbar and begins recording your actions
7. Perform the actions that you want recorded in the macro.
8. When finished, click the Stop Recording button on the toolbar.