Читать книгу Excel Macros For Dummies - Dick Kusleika - Страница 12

Macro Recording Basics

Оглавление

To start recording your first macro, you need to first find the Macro Recorder, which is on the Developer tab. Unfortunately, Excel comes out of the box with the Developer tab hidden — you may not see it on your version of Excel at first. If you plan to work with VBA macros, you'll want to make sure that the Developer tab is visible. To display this tab

1 Choose File ⇒ Options.

2 In the Excel Options dialog box, click Customize Ribbon.

3 In the list box on the right, place a check mark next to Developer.

4 Click OK to return to Excel.

Now that you have the Developer tab showing in the Excel Ribbon, you can start up the Macro Recorder by selecting Record Macro from the Developer tab. This activates the Record Macro dialog box, as shown in Figure 1-1.


FIGURE 1-1: The Record Macro dialog box.

Here are the four parts of the Record Macro dialog box:

 Macro Name: Excel gives a default name to your macro, such as Macro1, but you should give your macro a name more descriptive of what it actually does. For example, you might name a macro that formats a generic table as FormatTable. You have to follow a few rules when naming a macro. The first character must be a letter. Generally, special characters other than underscore aren't allowed. And the total number of characters can't be more than 255, although hopefully you don't get close to that limit.

 Shortcut Key: Every macro needs an event, or something to happen, for it to run. This event can be a button press, a workbook opening, or if you use this field, a keystroke combination. When you assign a shortcut key to your macro, entering that combination of keys triggers your macro to run. This is an optional field.

 Store Macro In: This Workbook is the default option. Storing your macro in This Workbook simply means that the macro is stored along with the active Excel file. The next time you open that particular workbook, the macro is available to run. Similarly, if you send the workbook to another user, that user can run the macro as well (provided the macro security is properly set by your user — more on that later in this chapter). You can also choose New Workbook to tell Excel to create a new workbook to store the macro or Personal Macro Workbook, a special workbook used to store macros you want access to all the time. See “Storing and Running Macros” later in this chapter for more on the Personal Macro Workbook.

 Description: This field is optional, but it can come in handy if you have numerous macros in a workbook or if you need to give a user a more detailed description about what the macro does.

With the Record Macro dialog box open, follow these steps to create a simple macro that enters your name into a worksheet cell:

1 Enter a new single-word name for the macro to replace the default Macro1 name.A good name for this example is MyName.

2 Assign this macro to the shortcut key Ctrl+Shift+N.You do this by entering uppercase N in the edit box labeled Shortcut Key.

3 Click OK.This closes the Record Macro dialog box and begins recording your actions.

4 Select cell B3 on your worksheet, type your name into the selected cell, and then press Enter.

5 Choose Developer ⇒ Code ⇒ Stop Recording (or click the Stop Recording button in the status bar).

Excel Macros For Dummies

Подняться наверх