Export (0) Print
Expand All
Expand Minimize

Workbook.Names Property

Gets a Microsoft.Office.Interop.Excel.Names collection that represents all the names in the workbook (including all worksheet-specific names).

Namespace: Microsoft.Office.Tools.Excel
Assembly: Microsoft.Office.Tools.Excel (in microsoft.office.tools.excel.dll)

public virtual Names Names { get; }

Property Value

A Microsoft.Office.Interop.Excel.Names collection that represents all the names in the workbook (including all worksheet-specific names).

The following code example uses the Names property to create three Microsoft.Office.Interop.Excel.Name objects that refer to different ranges on worksheet Sheet1. The example then iterates through every Microsoft.Office.Interop.Excel.Name in the workbook and displays the names in column A of worksheet Sheet1.

private void DisplayWorkbookNames()
{
    this.Names.Add("Name1", Globals.Sheet1.Range["B1", "B5"], true, missing,
        missing, missing, missing, missing, missing, missing, missing);
    this.Names.Add("Name2", Globals.Sheet1.Range["C1", "C5"], true, missing,
        missing, missing, missing, missing, missing, missing, missing);
    this.Names.Add("Name3", Globals.Sheet1.Range["D1", "D5"], true, missing,
        missing, missing, missing, missing, missing, missing, missing);

    for (int i = 1; i <= this.Names.Count; i++)
    {
        Globals.Sheet1.Range["A" + i.ToString(), missing].Value2 =
            this.Names.Item(i, missing, missing);
    }
}

Show:
© 2014 Microsoft