Name Property

Applies To

Property object, Reference object, VBComponent object, VBProject object.

Description

Returns or sets a String containing the name used in code to identify an object. For the VBProject object and the VBComponent object, read/write; for the Property object and the Reference object, read-only.

Remarks

The following table describes how the Name property setting applies to different objects.

Object

Result of using Name property setting

VBProject

Returns or sets the name of the active project.

VBComponent

Returns or sets the name of the component. An error occurs if you try to set the Name property to a name already being used or an invalid name.

Property

Returns the name of the property as it appears in the Property Browser. This is the value used to index the Properties collection. The name can't be set.

Reference

Returns the name of the reference in code. The name can't be set.


The default name for new objects is the type of object plus a unique integer. For example, the first new Form object is Form1, a new Form object is Form1, and the third text box control you create on a form is TextBox3.

An object's Name property must start with a letter and can be a maximum of 40 characters. It can include numbers and underline ( _ ) characters but can't include punctuation or spaces. Forms and modules can't have the same name as another public object such as Clipboard, Screen, or App. Although the Name property setting can be a keyword, property name, or the name of another object, this can create conflicts in your code.

See Also

Description property, Type property.

Example

The following example uses the Name property to return the name of the specified member of the VBComponents collection in a particular project.

Debug.Print Application.VBE.VBProjects(1).VBComponents(1).Name