Microsoft Office Tutorials and References
In Depth Information
Recording a Macro
Recording a Macro
The easiest way to get started learning about Excel macros is to use the macro recorder to
record a sequence of actions. Then you can play back the sequence — otherwise known as
running the macro.
The following hands-on demonstration gives newcomers a feel for how macros work. This
example demonstrates how to record a simple macro that inserts your name in the active cell.
Creating the macro
To create the macro, follow these steps:
1. Activate an empty cell.
2. Click the Record Macro button on the left side of the status bar.
Excel displays the Record Macro dialog box.
3. Enter a new single-word name for the macro, to replace the default Macro1 name.
A good name is MyName.
4. Assign this macro to the shortcut key Ctrl+Shift+N by typing an uppercase N in the edit
box labeled Shortcut Key.
5. Click OK to close the Record Macro dialog box and begin recording your actions.
6. Type your name in the selected cell and press Enter.
7. The macro is finished, so click the Stop Recording button on the status bar.
This macro is very simple. Most of the time, you record more actions than in this example.
Examining the macro
The macro was recorded in a new VBA module named Module1. If you’re interested, you can take
a look at the instructions that were recorded. To view the code in this module, you must activate
the Visual Basic Editor (VBE). Press Alt+F11 to toggle between the VBE and the Excel window.
In the VBE, the Project window displays a list of all open workbooks and add-ins. This list is
displayed as a tree diagram, which you can expand or collapse. The code that you recorded
previously is stored in Module1 in the current workbook. When you double-click Module1, the code in
the module is displayed in a Code window.
Figure 204-1 shows the recorded macro, as displayed in the Code window.
 
Search JabSto ::




Custom Search