NativeExcel2 for .Net Developer's Reference

INames.AddMethod(String, IRange)

Defines a new name. Returns an IName interface.

[Visual Basic]
FunctionAdd(_
ByValNameAsString,_
ByValRefersToAsIRange_
)AsIName
[C#]
INameAdd(
stringName,
IRangeRefersTo
);
[C++]
IName*Add(
String*Name,
IRange*RefersTo
);
[JScript]
functionAdd(
StringName,
IRangeRefersTo
):IName;

Parameters

Name
The text to use as the name. Names cannot include spaces and cannot look like cell references.
RefersTo
Describes what the name refers to.

Return Value

IName interface.

Example

This example adds new defined name for the workbook and use this name in the cell formula.

[C#]
IRange r = Workbook.Worksheets[1].Range["F10:H20"];
Workbook.Names.Add("MyName", r);
Workbook.Worksheets[1].Cells[3,4].Formula = "=SUM(MyName)";
[VisualBasic]
Dim r As IRange = Workbook.Worksheets(1).Range("F10:H20")
Workbook.Names.Add("MyName", r)
Workbook.Worksheets(1).Cells(3,4).Formula = "=SUM(MyName)"
[C++]
IRange* r = Workbook->Worksheets->Item[1]->Range->Item["F10:H20"];
Workbook->Names->Add(S"MyName", r);
Workbook->Worksheets->Item[1]->Cells->Item[3,4]->Formula = S"=SUM(MyName)";

See Also

INames Interface | NativeExcel Namespace | INames.Add Overload List