Microsoft Office Tutorials and References
In Depth Information
3.1.2.5 UserForm objects
Class modules are code modules that contain code related to custom objects. As we will see, the
Excel object model has a great many built-in objects (almost 200), such as workbook objects,
worksheet objects, chart objects, font objects, and so on. It is also possible to create custom
objects and endow them with various properties. To do so, we would place the appropriate code
within a class module.
However, since creating custom objects is beyond the scope of this topic, we will not be using
class modules. (For an introduction to object-oriented programming using VB, allow me to
suggest my book, Concepts of Object-Oriented Programming with Visual Basic , published by
Springer-Verlag, New York.)
3.1.2.5 UserForm objects
As you no doubt know, Excel contains a great many built-in dialog boxes. It is also possible to
create custom dialog boxes, also called forms or UserForms. This is done by creating UserForm
objects. Figure 3-3 s hows the design environment for the Select Special UserForm that we
mentioned in Chapter 1 .
Figure 3-3. A UserForm dialog box
The large window on the upper-center in Figure 3-3 contains the custom dialog box (named
dlgSelectSpecial) in its design mode. There is a floating Toolbox window on the right that
contains icons for various Windows controls.
To place a control on the dialog box, simply click on the icon in the Toolbox and then drag and
size a rectangle on the dialog box. This rectangle is replaced by the control of the same size as the
rectangle. The properties of the UserForm object or of any controls on the form can be changed by
selecting the object and making the changes in the Properties window, which we discuss in the
next section.
In addition to the form itself and its controls, a UserForm object contains code that the VBA
programmer writes in support of these objects. For instance, a command button has a Click event
that fires when the user clicks on the button. If we place such a button on the form, then we must
write the code that is run when the Click event fires; otherwise, clicking the button does nothing.
 
 
Search JabSto ::




Custom Search