Chapter 41: Creating UserForms
855
Try it with a few more selections. Notice that if you click Cancel, the UserForm is dismissed, and
no changes are made.
Making the macro available from a worksheet button
At this point, everything should be working properly. However, you have no quick and easy way
to execute the macro. A good way to execute this macro would be from a button on the worksheet.
You can use the following steps:
- Choose Developer ➪ Controls ➪ Insert and click the Button control in the Form
Controls group. - Click and drag in the worksheet to create the button.
- Excel displays the Assign Macro dialog box.
- In the Assign Macro dialog box, select ShowUserForm and then click OK.
- (Optional) At this point, the button is still selected, so you can change the text to
make it more descriptive. You can also right-click the button at any time to change
the text.
After performing the preceding steps, clicking the button executes the macro and displays the
UserForm.
Cross-Reference
The button in this example is from the Form Controls group. Excel also provides a button in the ActiveX
Controls group. See Chapter 42 for more information about the ActiveX Controls group. n
Making the macro available on your Quick Access
toolbar
If you would like to use this macro while other workbooks are active, you may want to add a but-
ton to your Quick Access toolbar. Use the following steps:
- Make sure that the workbook containing the macro is open.
- Right-click anywhere on the Ribbon and choose Customize Quick Access Toolbar
from the shortcut menu. The Excel Options dialog box appears, with the Quick Access
Toolbar section selected. - Choose Macros from the Choose Commands From drop-down menu on the left.
You’ll see your macro listed.