Muokkaa

Jaa


Names.Add method (Excel)

Defines a new name for a range of cells.

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 Specifies the text, in English, to use as the name if the NameLocal parameter is not specified. Names cannot include spaces and cannot be formatted as cell references.
RefersTo Optional Variant Describes what the name refers to, in English, using A1-style notation, if the RefersToLocal, RefersToR1C1, and RefersToR1C1Local parameters are not specified.

NOTE: Nothing is returned if the reference does not exist.
Visible Optional Variant True specifies that the name is defined as visible. False specifies that the name is defined as hidden. A hidden name does not appear in 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 (Sub procedure)

  • 3 or omitted - None (the name does not refer to a user-defined function or macro)

ShortcutKey Optional Variant Specifies 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 the MacroType argument equals 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 English. Excel creates a new category if the specified category does not exist.
NameLocal Optional Variant Specifies the localized text to use as the name if the Name parameter is not specified. Names cannot include spaces and cannot be formatted as cell references.
RefersToLocal Optional Variant Describes what the name refers to, in localized text using A1-style notation, if the RefersTo, RefersToR1C1, and RefersToR1C1Local parameters are not specified.
CategoryLocal Optional Variant Specifies the localized text that identifies the category of a custom function if the Category parameter is not specified.
RefersToR1C1 Optional Variant Describes what the name refers to, in English using R1C1-style notation, if the RefersTo, RefersToLocal, and RefersToR1C1Local parameters are not specified.
RefersToR1C1Local Optional Variant Describes what the name refers to, in localized text using R1C1-style notation, if the RefersTo, RefersToLocal, and RefersToR1C1 parameters are not specified.

Return value

A Name 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.

Sub MakeRange() 
 
    ActiveWorkbook.Names.Add _ 
        Name:="tempRange", _ 
        RefersTo:="=Sheet1!$A$1:$D$3" 
 
End Sub

Support and feedback

Have questions or feedback about Office VBA or this documentation? Please see Office VBA support and feedback for guidance about the ways you can receive support and provide feedback.