편집

다음을 통해 공유


Add method (Microsoft Forms)

Adds or inserts a Tab or Page in a TabStrip or MultiPage, or adds a control by its programmatic identifier (ProgID) to a page or form.

Syntax

For MultiPage, TabStrip:
SetObject = object. Add( [ Name [, Caption [, index ]]] )

For other controls:
SetControl = object. Add(ProgID [, Name [, Visible ]] )

The Add method syntax has these parts:

Part Description
object Required. A valid object name.
Name Optional. Specifies the name of the object being added. If a name is not specified, the system generates a default name based on the rules of the application where the form is used.
Caption Optional. Specifies the caption to appear on a tab or a control. If a caption is not specified, the system generates a default caption based on the rules of the application where the form is used.
index Optional. Identifies the position of a page or tab within a Pages or Tabs collection. If an index is not specified, the system appends the page or tab to the end of the Pages or Tabs collection and assigns the appropriate index value.
ProgID Required. Programmatic identifier. A text string with no spaces that identifies an object class. The standard syntax for a ProgID is <Vendor>.<Component>.<Version>. A ProgID is mapped to a class identifier (CLSID).
Visible Optional. True if the object is visible (default). False if the object is hidden.

Settings

ProgID values for individual controls are:

Control ProgID value
CheckBox Forms.CheckBox.1
ComboBox Forms.ComboBox.1
CommandButton Forms.CommandButton.1
Frame Forms.Frame.1
Image Forms.Image.1
Label Forms.Label.1
ListBox Forms.ListBox.1
MultiPage Forms.MultiPage.1
OptionButton Forms.OptionButton.1
ScrollBar Forms.ScrollBar.1
SpinButton Forms.SpinButton.1
TabStrip Forms.TabStrip.1
TextBox Forms.TextBox.1
ToggleButton Forms.ToggleButton.1

Remarks

For a MultiPage control, the Add method returns a Page object. For a TabStrip, it returns a Tab object. The index value for the first Page or Tab of a collection is 0, the value for the second Page or Tab is 1, and so on.

For the Controls collection of an object, the Add method returns a control corresponding to the specified ProgID. The AddControl event occurs after the control is added.

You can add a control to a user form's Controls collection at design time, but you must use the Designer property of the Microsoft Visual Basic for Applications Extensibility Library to do so. The Designer property returns the UserForm object.

The following syntax will return the Text property of the specified control:

userform1.thebox.text

If you add a control at run time, you must use the exclamation syntax to reference properties of that control. For example, to return the Text property of a control added at run time, use the following syntax:

userform1!thebox.text

Note

You can change a control's Name property at run time only if you added that control at run time with the Add method.

See also

Support and feedback

Have questions or feedback about Office VBA or this documentation? Please see Office VBA support and feedback for guidance about the ways you can receive support and provide feedback.