Add Method (Names Collection)

Applies To

Names collection object.

Description

Defines a new name. Returns a Name object.

Syntax

expression.Add(Name, RefersTo, Visible, MacroType, ShortcutKey, Category, NameLocal, RefersToLocal, CategoryLocal, RefersToR1C1, RefersToR1C1Local)

expression Required. An expression that returns a Names object.

Name Optional Variant. Required if NameLocal isn't specified. The text to use as the name (in the language of the macro). Names cannot include spaces and cannot look like cell references.

RefersTo Optional Variant. Required unless one of the other RefersTo arguments is specified. Describes what the name refers to (in the language of the macro, using A1-style notation).

Visible Optional Variant. True to define the name normally. False to define the name as a hidden name (that is, it doesn't appear in either the Define Name, Paste Name, or Goto dialog box). The default value is True.

MacroType Optional Variant. The macro type, as shown in the following table.

Value

Meaning

1

User-defined function (Function procedure)

2

Macro (also known as Sub procedure)

3 or omitted

None (that is, the name doesn't refer to a user-defined function or macro)


ShortcutKey Optional Variant. The macro shortcut key. Must be a single letter, such as "z" or "Z". Applies only for command macros.

Category Optional Variant. The category of the macro or function if MacroType is 1 or 2. The category is used in the Function Wizard. Existing categories can be referred to either by number (starting at 1) or by name (in the language of the macro). Microsoft Excel creates a new category if the specified category doesn't already exist.

NameLocal Optional Variant. Required if Name isn't specified. The text to use as the name (in the language of the user). Names cannot include spaces and cannot look like cell references.

RefersToLocal Optional Variant. Required unless one of the other RefersTo arguments is specified. Describes what the name refers to (in the language of the user, using A1-style notation).

CategoryLocal Optional Variant. Required if Category isn't specified. Text identifying the category of a custom function in the language of the user.

RefersToR1C1 Optional Variant. Required unless one of the other RefersTo arguments is specified. Describes what the name refers to (in the language of the macro, using R1C1-style notation).

RefersToR1C1Local Optional Variant. Required unless one of the other RefersTo arguments is specified. Describes what the name refers to (in the language of the user, using R1C1-style notation).

Example

This example defines a new name for the range A1:D3 on Sheet1 in the active workbook.

ActiveWorkbook.Names.Add _
    Name:="tempRange", _
    RefersTo:="=Sheet1!$A$1:$D$3"