Add Method (Names Collection)

Applies To

Names Collection.

Description

Defines a new name. Returns a Name object.

Syntax

object.Add(name, refersTo, visible, macroType, shortcutKey, category, nameLocal, refersToLocal, categoryLocal, refersToR1C1, refersToR1C1Local)

object

Required. The Names object.

name

Required (unless nameLocal is 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

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. If True or omitted, Microsoft Excel defines the name normally. If False, the name is defined as a hidden name (it does not appear in the Define Name, Paste Name, or Goto dialog boxes).

macroType

Optional. Specifies 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 does not refer to a user-defined function or macro)


shortcutKey

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

category

Specifies 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 by number (starting at one), or by name (in the language of the macro). Microsoft Excel creates a new category if the specified category does not already exist.

nameLocal

Required if name is not 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

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

Required if category is not specified. Text identifying the category of a custom function in the language of the user.

refersToR1C1

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

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.


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