18.11.2014 Views

Microsoft Office

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Creating UserForms 41<br />

5. In the Macros dialog box, select ShowUserForm from the list of macros and then click OK.<br />

The UserForm appears.<br />

6. Make your choice and click OK.<br />

Try it with a few more selections. Notice that if you click Cancel, the UserForm is dismissed, and no<br />

changes are made.<br />

Making the macro available from a worksheet button<br />

At this point, everything should be working properly. However, you have no quick and easy way to execute<br />

the macro. A good way to execute this macro would be from a button on the worksheet. You can use the<br />

following steps:<br />

1. Choose Developer ➪ Controls ➪ Insert and click the Button control in the Form Controls<br />

group.<br />

2. Click and drag in the worksheet to create the button.<br />

3. Excel display the Assign Macro dialog box.<br />

4. In the Assign Macro dialog box, select ShowUserForm and click OK.<br />

At this point, the button is still selected, so you can change the text to make it more<br />

descriptive. You can also right-click the button at any time to change the text.<br />

After performing the preceding steps, clicking the button executes the macro and displays the UserForm.<br />

CROSS-REF<br />

group.<br />

The button in this example is from the Form Controls group. Excel also provides a button in<br />

the ActiveX Controls group. See Chapter 42 for more information about the ActiveX Controls<br />

Making the macro available on your Quick Access Toolbar<br />

You can also add a button to your Quick Access Toolbar (QAT) that, when clicked, executes your macro.<br />

Unfortunately, the button works only when the workbook that contains the macro is active. To add a macro<br />

button to your QAT, use the following steps:<br />

1. Make sure that the workbook containing the macro is open.<br />

2. Right-click anywhere in the Ribbon and then select Customize Quick Access Toolbar. The<br />

Excel Options dialog box appears, with the Customization setting selected.<br />

3. Choose Macros from the drop-down menu on the left (labeled Choose Commands From).<br />

You’ll see your macro listed.<br />

4. Select the macro’s name and click Add to adds the item to the list on the right.<br />

5. If you’d like to change the icon, click Modify and choose a new image. You can also change<br />

the Display Name.<br />

6. Click OK to close the Excel Options dialog box. After performing these steps, your QAT will<br />

have a new icon.<br />

731

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!