UserForm Object

A UserFormobject is a window or dialog box that makes up part of an application's user interface. The UserFormscollection is a collection whose elements represent each loaded UserForm in an application. The UserForms collection has a Count property, an Item property, and an Add method. Count specifies the number of elements in the collection; Item (the default member) specifies a specific collection member; and Add places a new UserForm element in the collection.


UserForm UserForms [ .Item ] (index) The placeholder index represents an integer with a range from 0 to UserForms.Count - 1. Item is the default member of the UserForms collection and need not be specified.


You can use the UserForms collection to iterate through all loaded user forms in an application. It identifies an intrinsic globalvariable named UserForms. You can pass UserForms(index) to a function whoseargument is specified as a UserForm class. User forms have properties that determine appearance such as position, size, and color; and aspects of their behavior. User forms can also respond to events initiated by a user or triggered by the system. For example, you can write code in the Initialize event procedure of the UserForm to initializemodule-level variables before the UserForm is displayed. In addition to properties and events, you can use methods to manipulate user forms using code. For example, you can use the Move method to change the location and size of a UserForm. When designing user forms, set the BorderStyle property to define borders, and set the Caption property to put text in the title bar. In code, you can use the Hide and Show methods to make a UserForm invisible or visible at run time. UserForm is an Object data type. You can declare variables as type UserForm before setting them to an instance of a type of UserForm declared at design time. Similarly, you can pass an argument to a procedure as type UserForm. You can create multiple instances of user forms in code by using the New keyword in Dim, Set, and Static statements. You can access the collection of controls on a UserForm using the Controls collection. For example, to hide all the controls on a UserForm, use code similar to the following:

For Each Control in UserForm1.Controls
    Control.Visible = False
Next Control