Recording a Macro

The easiest way to create a macro is to use Excel's macro recorder . You simply turn on the recorder, type a name for the macro, perform the task you want to record, and then stop the recorder. The following instructions lead you step-by-step through the process of recording a macro:

  1. Open the Tools menu, point to Macro , and choose Record New Macro . The Record Macro dialog box appears, as shown in Figure 13.1, prompting you to name the macro.

    Figure 13.1. Type a name for your macro in Excel's Record Macro dialog box.

    graphics/13fig01.gif

  2. Type a unique, descriptive, and brief name for your macro, up to 64 characters (no spaces). The macro name must start with a letternever a number. The macro recorder supplies a default nameMacro1, Macro2, and so on, as you keep recording macrosbut nondescriptive names such as these are not very helpful when you're trying to determine the purpose of each macro.

  3. Open the Store Macro In drop-down list, and choose one of the following options:

    Personal Macro Workbook to make the macro available in all workbooks.

    New Workbook to have Excel create a new workbook and store the macro in that workbook.

    This Workbook to make the macro available only in the currently open workbook.

  4. To assign a shortcut key to the macro, click in the Shortcut key: Ctrl+ box and hold down the Shift key while pressing the letter key that you want to use in combination with the Ctrl key to launch your macro. This assigns the macro a Ctrl+Shift+ letter key shortcut.

  5. Click in the Description text box, and type a brief description of the macro's function (the task it performs ).

  6. Click the OK button. The Stop Recording toolbar appears with buttons for stopping the recording and for switching between relative and absolute cell references, as shown in Figure 13.2. (If the toolbar does not appear, right-click any toolbar and click Stop Recording .)

    Figure 13.2. Excel's Stop Recording toolbar can turn off recording when you're done.

    graphics/13fig02.jpg

  7. Perform the task whose steps you want to record. You can select menu commands, click toolbar buttons, and press keystrokes to enter commands. To select a cell, click it. To select a range of cells, drag over the cells . You can also type entries and select objects, such as charts and clip art.

  8. When you are finished performing the steps, click the Stop Recording button, or open the Tools menu, point to Macro , and click Stop Recording . Excel saves your macro with the name you entered in step 2.

Caution

graphics/cman.gif

When specifying a shortcut key, avoid using keys that Excel has already assigned to other tasks , such as Ctrl+C to copy or Ctrl+P to print. By holding down the Shift key when assigning a keystroke, you avoid most conflicts. For example, if you press Shift+P, Excel assigns the Ctrl+Shift+P shortcut to the macro. If you were to press P, Excel would assign the Ctrl+P keystroke to the macro, and whenever you pressed Ctrl+P, Excel would run the macro rather than print a worksheet.


Note

graphics/nman.gif

Excel macros automatically record any cell selections by using absolute references. If you want to use relative references, click the Relative Reference button on the Stop Recording toolbar. You can click this button repeatedly to switch back and forth from absolute to relative references. For an explanation of the difference between absolute and relative cell references, see Chapter 6, "Automating Calculations with Formulas and Functions."




Absolute Beginner's Guide to Microsoft Office Excel 2003
Absolute Beginners Guide to Microsoft Office Excel 2003
ISBN: 0789729415
EAN: 2147483647
Year: 2002
Pages: 189

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net