Excel 2010 Bible

(National Geographic (Little) Kids) #1

Chapter 39: Introducing Visual Basic for Applications


803


Warning
Shortcut keys assigned to macros take precedence over built-in shortcut keys. For example, if you assign Ctrl+S
to a macro, then you cannot use the key combination to save your workbook. n


l (^) Store Macro In: The location for the macro. Your choices are the current workbook, your
Personal Macro Workbook (See “Storing macros in your Personal Macro Workbook,” later
in this chapter), or a new workbook.
l Description: A description of the macro (optional).
To begin recording your actions, click OK; your actions within Excel are converted to VBA code.
When you finish recording the macro, choose Developer ➪ Code ➪ Stop Recording. Or, you can
click the Stop Recording button on the status bar. This button replaces the Start Recording button
while your macro is being recorded.
Note
Recording your actions always results in a new Sub procedure. You can’t create a Function procedure by
using the macro recorder. Function procedures must be created manually. n
Recording a macro: A simple example
This example demonstrates how to record a very simple macro that inserts your name in the active
cell.
To create the macro, start with a new workbook and follow these steps:



  1. Activate an empty cell.


Note
Select the cell to be formatted before you start recording your macro. This step is important. If you select a cell
while the macro recorder is turned on, the actual cell that you select will be recorded into the macro. In such
a case, the macro would always format that particular cell, and it would not be a general-purpose macro. n



  1. Choose Developer ➪ Code ➪ Record Macro. Excel displays the Record Macro dialog
    box. (Refer to Figure 39.7.)

  2. Enter a new single-word name for the macro, to replace the default Macro1 name. A
    good name is MyName.

  3. Assign this macro to the shortcut key Ctrl+Shift+N by entering an uppercase N in
    the Shortcut Key field.

  4. Click OK to close the Record Macro dialog box and begin recording your actions.

  5. Type your name into the selected cell and then press Enter.

  6. Choose Developer ➪ Code ➪ Stop Recording (or click the Stop Recording button
    on the status bar).

Free download pdf