18.11.2014 Views

Microsoft Office

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Creating UserForms 41<br />

8. Add a CommandButton object to the UserForm and change the following properties for the<br />

CommandButton:<br />

Property<br />

Name<br />

Caption<br />

Default<br />

Change To<br />

OKButton<br />

OK<br />

True<br />

9. Make other adjustments so that the form looks good to you. You can change the size of the<br />

form or move or resize the controls.<br />

FIGURE 41.8<br />

A Label control, after changing its Font properties.<br />

Testing the UserForm<br />

At this point, the UserForm has all the necessary controls. But what’s missing is a way to display the<br />

UserForm. While you’re developing the UserForm, you can press F5 to display it and see how it looks.<br />

This section explains how to write a VBA Sub procedure to display the UserForm when Excel is active.<br />

1. Insert a VBA module by choosing Insert ➪ Module.<br />

2. In the empty module, enter the following code:<br />

Sub ShowAboutBox()<br />

AboutBox.Show<br />

End Sub<br />

3. Activate Excel (Alt+F11 is one way).<br />

4. Choose Developer ➪ Code ➪ Macros to display the Macros dialog box. Or you can press<br />

Alt+F8 or click the Play Macro button in the status bar.<br />

5. In the Macros dialog box, select ShowAboutBox from the list of macros and click Run. The<br />

UserForm then appears.<br />

725

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

Saved successfully!

Ooh no, something went wrong!