O'Reilly logo

Word 2000 in a Nutshell by Walter Glenn

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

UserForms

Word UserForms are actually Office UserForms, which are hosted by most Office applications. They have a different object model than Word, so if you start working with them extensively, you will need to familiarize yourself with the Forms object library (MSForms in the Libraries drop-down box in the VBA window). But you can create and work with UserForms in the VBA window without using the Forms object model in code, and these forms are very useful for intermediate and advanced Word programming. UserForms allow you to go beyond a simple message box or input box and present users with a more extensive dialog box with (for example) combo boxes or list boxes where items can be selected, and text boxes for entering values.

To create a UserForm, open the VBA window, select the appropriate document or template in the Project Explorer, and click the Insert UserForm button on the toolbar. A new form opens (Figure 18-10), called UserForm1 (or a higher number, if there already are some forms for this template). When the UserForm has the focus, a Toolbox appears, with a selection of controls you can place on the form.

A newly created UserForm with several controls

Figure 18-10. A newly created UserForm with several controls

UserForms (and controls placed on them) have several useful events:

Initialize

The Initialize event of the form, which fires when the form is opened, is useful for filling in default values for controls on the ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required