Syntax

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

expression A variable that represents a Names object.

Parameters

Name Required/Optional Data Type Description
Name Optional Variant 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 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).
Note
Nothing is returned if the reference does not exist.
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, determined by one of the following values:
  • 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 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 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 if Category isn't specified. Text identifying the category of a custom function in the language of the user.
RefersToR1C1 Optional Variant 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 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).

Return Value
A object that represents the new name.

Example

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

Note
Nothing is returned if Sheet1 does not exist.
Visual Basic for Applications
Sub MakeRange() ActiveWorkbook.Names.Add _ Name:="tempRange", _ RefersTo:="=Sheet1!$A$1:$D$3" End Sub

See also: