Executing a procedure by clicking an object

Excel provides a variety of objects that you can place on a worksheet or chart sheet, and you can attach a macro to any of these objects. These objects are available from three toolbars:

♦ The Drawing toolbar

♦ The Forms toolbar

♦ The Control Toolbox toolbar

In addition, you can assign a macro to pictures that you place on the worksheet by choosing the Insert ^ Picture command. Right-click the picture and then choose Assign Macro.

The Control Toolbox toolbar contains ActiveX controls, which are similar to the controls that you use in a UserForm.The Forms toolbar, which is included for compatibility purposes, contains similar controls (which are not ActiveX controls).The controls on the Forms toolbar were designed for Excel 5 and Excel 95. However, they can still be used in later versions (and may be preferable in some cases).The discussion that follows applies to the Button control from the Forms toolbar. Refer to Chapter 13 for information about using ActiveX controls on worksheets.

To assign a procedure to a Button object (which is on the Forms toolbar), follow these steps:

1. Make sure that the Forms toolbar is displayed.

2. Click the Button tool on the Forms toolbar.

3. Drag in the worksheet to create the button.

If you press Alt while dragging, the button will conform to the sheet's grid-lines. Or, press Shift while dragging to force a perfectly square button.

Excel jumps right in and displays the Assign Macro dialog box. Select the macro that you want to assign to the button and then click OK.

To assign a macro to a shape, create a shape from the Drawing toolbar. Right-click the shape and then choose Assign Macro from the shortcut menu.

Was this article helpful?

0 0

Post a comment