18.11.2014 Views

Microsoft Office

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Introducing Visual Basic for Applications 39<br />

NOTE<br />

The Personal Macro Workbook normally is in a hidden window (to keep it out of the way).<br />

To record the macro in your Personal Macro Workbook, select the Personal Macro Workbook option in the<br />

Record Macro dialog box before you start recording. This option is in the Store Macro In drop-down box.<br />

If you store macros in the Personal Macro Workbook, you don’t have to remember to open the Personal<br />

Macro Workbook when you load a workbook that uses macros. When you want to exit, Excel asks whether<br />

you want to save changes to the Personal Macro Workbook.<br />

Assigning a macro to a shortcut key<br />

When you begin recording a macro, the Record Macro dialog box gives you an opportunity to provide a<br />

shortcut key for the macro. If you’d later like to change the shortcut key or provide a shortcut key for a<br />

macro that doesn’t have one:<br />

1. Press Alt+F8 to display the Macro dialog box.<br />

2. In the Macro dialog box, select the macro name from the list.<br />

3. Click the Options button, and Excel displays its Macro Options dialog box (see Figure<br />

39.10).<br />

4. Specify the shortcut key and click OK to return to the Macro dialog box.<br />

5. Click Cancel to close the Macro dialog box.<br />

FIGURE 39.10<br />

Use the Macro Options dialog box to add or change a shortcut key for a macro.<br />

Assigning a macro to a button<br />

After you record a macro and test it, you may want to assign the macro to a button placed in a worksheet.<br />

You can follow these steps to do so:<br />

1. If the macro is a general-purpose macro that you plan to use in more than one workbook,<br />

make sure that the macro is stored in your Personal Macro Workbook.<br />

2. Choose Developer ➪ Controls ➪ Insert and click the Button control from the Form<br />

Controls section (see Figure 39.11).<br />

3. Draw the button on the worksheet. Excel displays the Assign Macro dialog box.<br />

4. In the Assign Macro dialog box, select the macro from the list.<br />

5. Click OK to close the Assign Macro dialog box.<br />

693

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!