Page 303 - Excel Workbook for Dummies
P. 303

32_798452 ch22.qxp  3/13/06  7:48 PM  Page 286
                286       Part VII: Macros and Visual Basic for Applications
                                    Note that the macro recorder does not record the keystrokes or mouse actions you
                                    take to accomplish an action, but only the VBA code required to perform the action
                                    itself. This means that any mistakes that you make while taking an action are not
                                    recorded as part of the macro. If, for example, you make a typing error and then edit it
                                    while the macro recorder is on, only the corrected entry shows up in the macro with-
                                    out the original mistakes and steps taken to remedy them.

                                    The macros that you create with the macro recorder can be stored either as part of
                                    the current workbook, in a new workbook, or in a special, globally available Personal
                                    Macro Workbook named PERSONAL.XLS that’s stored in a folder called XLSTART on
                                    your hard disk. When you record a macro as part of your Personal Macro Workbook,
                                    you can run that macro from any workbook that you have open. (This is because the
                                    PERSONAL.XLS workbook is secretly opened whenever you launch Excel and, although
                                    it remains hidden, its macros are therefore always available.) When you record macros
                                    as part of the current workbook or a new workbook, you can run those macros only
                                    when the workbook in which they were recorded is open in Excel.

                                    When you create a macro with the macro recorder, you decide not only the workbook
                                    in which to store the macro but also what name and shortcut keystrokes to assign to
                                    the macro you are creating. When assigning a name for your macro, you use the same
                                    guidelines as when assigning a standard range name to a cell range in your worksheet.
                                    When assigning a shortcut keystroke to run the macro, you can assign the Ctrl key
                                    plus a lowercase letter between a and z, such as Ctrl+q (which is displayed as Ctrl+Q,
                                    although you press just Ctrl+q) or the Ctrl key plus an uppercase letter between A and
                                    Z as in Ctrl+Q (which appears as Ctrl+Shift+Q because you must press all three keys).
                                    You cannot, however, assign the Ctrl key plus a punctuation or number key (such as
                                    Ctrl+1 or Ctrl+/) to your macro.


                          Try It

                                    Exercise 22-1: Recording a New Macro

                                    If Excel is not currently running, launch the program. Use Sheet1 of the new Book1
                                    workbook to practice recording and playing back a new macro that enters the
                                    Company Name (Mind Over Media, Inc., in this case) in 12-point bold type and
                                    then centers the text across rows A through E with the Merge and Center button:
                                     1. Choose the Tools➪Macro➪Record New Macro menu command to open the
                                         Record Macro dialog box.
                                     2. Replace the temporary macro name, Macro1, in the Macro Name text box with
                                         Company_Name (be sure to enter an underscore character between Company
                                         and Name and not a space as you would when naming a cell range in the work-
                                         sheet) and then click the Shortcut Key text box.
                                     3. Type an uppercase C so that the Shortcut key appears as Ctrl+Shift+C.
                                     4. Select Personal Macro Workbook on the Store Macro In option’s drop-down list.
                                         If you store a macro in the current workbook or a new workbook, you can only
                                         use the macro while that particular workbook is open in Excel. When you save a
                                         macro in the Personal Macro Workbook, you can use the macro in any workbook
                                         you have open.
                                     5. Select the Description text box and then insert the following additional informa-
                                         tion before the stock Macro recorded followed by the current date and by fol-
                                         lowed by your name:
                                         Enter company name in 12-point bold centered across five columns -
   298   299   300   301   302   303   304   305   306   307   308