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

Assigning a macro to a button and other form controls

Оглавление

When you create macros, you may want to have a clear and easy way to run each macro. A basic button can provide a simple but effective user interface.

As luck would have it, Excel offers a set of form controls designed specifically for creating user interfaces directly on worksheets. There are several different types of form controls, from buttons (the most commonly used control) to scrollbars.

The idea behind using a form control is simple: You place a form control on a worksheet and then assign a macro to it — that is, a macro you’ve already recorded. When a macro is assigned to the control, that macro is executed, or played, when the control is clicked.

Take a moment to create a button for the AddTotalRelative macro you created earlier. Here’s how:

1 Click the Insert button on the Developer tab. (See Figure 1-7.)

2 Select the Button Form Control from the drop-down list that appears.

3 Click the location where you want to place your button.When you drop the button control onto your worksheet, the Assign Macro dialog box, shown in Figure 1-8, opens and asks you to assign a macro to this button.

4 Select the macro you want to assign to the button and then click OK.


FIGURE 1-7: You can find the form controls on the Developer tab.


FIGURE 1-8: Assign a macro to the newly added button.

Excel Macros For Dummies

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