Executing the procedure from a button or shape

You can create still another means for executing the macro by assigning the macro to a button (or any other shape) on a worksheet. To assign the macro to a button, follow these steps:

1. Activate a worksheet.

2. Add a button from the Forms toolbar.

To display the Forms toolbar, right-click any toolbar and choose Forms from the shortcut menu.

3. Click the Button tool on the Forms toolbar.

4. Drag in the worksheet to create the button.

After you add the button to your worksheet, Excel jumps right in and displays the Assign Macro dialog box shown in Figure 5-5.

5. Select the macro you want to assign to the button.

Clicking the button will execute the macro.

Available macro names

Forms toolbar Button

Suggested macro name

Figure 5-5:

When you add a button to a worksheet, Excel automatically displays the Assign Macro dialog box.

Available macro names

Forms toolbar Button

Suggested macro name

Figure 5-5:

When you add a button to a worksheet, Excel automatically displays the Assign Macro dialog box.

You can also assign a macro to any other shape or object. For example, assume you'd like to execute a macro when the user clicks a Rectangle object.

1. Add the Rectangle to the worksheet.

Use the Rectangle button on the Drawing toolbar.

2. Right-click the rectangle.

3. Choose Assign Macro from its shortcut menu.

4. Select the macro from the Assign Macro dialog box.

After performing these steps, clicking the rectangle will execute the macro.

0 0

Post a comment