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 />

FIGURE 41.7<br />

The Properties window for a CommandButton control.<br />

When you set properties by using the Property window, you’re setting properties at design time. You can<br />

also use VBA to change the properties of controls while the UserForm is displayed (that is, at run time).<br />

A complete discussion of all the properties is well beyond the scope of this book — and it would indeed be<br />

very dull reading. To find out about a particular property, select it in the Property window and press F1.<br />

The Help for UserForm controls is extremely thorough.<br />

Handling events<br />

When you insert a UserForm, that form can also hold VBA Sub procedures to handle the events that are<br />

generated by the UserForm. An event is something that occurs when the user manipulates a control. For<br />

example, clicking a button causes an event. Selecting an item in a list box control also triggers an event. To<br />

make a UserForm useful, you must write VBA code to do something when an event occurs.<br />

Event-handler procedures have names that combine the control with the event. The general form is the control’s<br />

name, followed by an underscore, and then the event name. For example, the procedure that is executed<br />

when the user clicks a button named MyButton is MyButton_Click.<br />

723

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

Saved successfully!

Ooh no, something went wrong!