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 group.

To display the Forms group, select DeveloperOControlsOInsert (See Figure 5-5)

3. Click the Button tool in the Forms group.

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-6.

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

Clicking the button will execute the macro.

Figure 5-5:

The Ribbon showing the Developer tab, after clicking the Insert dropdown on the Controls chunk.

Figure 5-5:

The Ribbon showing the Developer tab, after clicking the Insert dropdown on the Controls chunk.

Chunks Con Sus Opciones Excel 2007

Note that the dropdown shows two sets of controls. Form controls and ActiveX controls. These two groups of controls look similar, but they are actually very different. In practice, the Form controls are easier to use.

Figure 5-6:

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.

Insert a rectangle by selecting InsertOIllustrationsOShapes and clicking on a rectangle.

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.

Figure 5-6:

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

0 0

Post a comment