Class Name (Excel VBA)

The class Name represents a defined name for a range of cells. Names can be either built-in names—such as Database, Print_Area, and Auto_Open—or custom names.

Member in collection

Item

To use a Name class variable it first needs to be instantiated, for example

Dim nam as Name
Set nam = ActiveWorkbook.Names(Index:=1)

The following procedures can be used to set variables of type Name: Names.Add and Names.Item.

For Each

Here is an example of processing the Name items in a collection.

Set newSheet = Worksheets.Add 
i = 1 
For Each nm In ActiveWorkbook.Names 
 newSheet.Cells(i, 1).Value = nm.Name 
 newSheet.Cells(i, 2).Value = "'" & nm.RefersTo 
 i = i + 1 
Next 
newSheet.Columns("A:B").AutoFit

Methods

Delete - Deletes the object.

Names.Add - Defines a new name for a range of cells.

Names.Item - Returns a single Name object from a Names collection.

Properties

Value (Default member) - Returns or sets a String value that represents the formula that the name is defined to refer to.

Category returns or sets the category for the specified name in the language of the macro. The name must refer to a custom function or command.

CategoryLocal returns or sets the category for the specified name, in the language of the user, if the name refers to a custom function or command.

Comment returns or sets the comment associated with the name.

Index returns a Long value that represents the index number of the object within the collection of similar objects.

MacroType returns or sets what the name refers to.

Name returns or sets a String value representing the name of the object.

NameLocal returns or sets the name of the object, in the language of the user.

RefersTo returns or sets the formula that the name is defined to refer to, in the language of the macro and in A1-style notation, beginning with an equal sign. Read/write String.

RefersToLocal returns or sets the formula that the name refers to. The formula is in the language of the user, and it's in A1-style notation, beginning with an equal sign. Read/write String.

RefersToR1C1 returns or sets the formula that the name refers to. The formula is in the language of the macro, and it's in R1C1-style notation, beginning with an equal sign. Read/write String.

RefersToR1C1Local returns or sets the formula that the name refers to. This formula is in the language of the user, and it's in R1C1-style notation, beginning with an equal sign. Read/write String.

RefersToRange returns the Range object referred to by a Name object.

ShortcutKey returns or sets the shortcut key for a name defined as a custom Microsoft Excel 4.0 macro command.

ValidWorkbookParameter returns True if the specified Name object is a valid workbook parameter.

Visible returns or sets a Boolean value that determines whether the object is visible.

WorkbookParameter returns or sets the specified Name object as a workbook parameter.

Names.Count returns a Long value that represents the number of objects in the collection.

Range - Represents a cell, a row, a column, a selection of cells containing one or more contiguous blocks of cells, or a 3D range.