NamedRange.Item Property

 

Gets a Microsoft.Office.Interop.Excel.Range that represents a range at an offset to the NamedRange control.

Namespace:   Microsoft.Office.Tools.Excel
Assembly:  Microsoft.Office.Tools.Excel (in Microsoft.Office.Tools.Excel.dll)

NamedRange_ItemType Item { get; }

Property Value

Type: Microsoft.Office.Tools.Excel.NamedRange_ItemType

A Microsoft.Office.Interop.Excel.Range that represents a range at an offset to the NamedRange control.

The Item property is intended to be used with the following parameters.

Parameter

Description

RowIndex

The index number of the cell you want to access, in order from left to right. NamedRange.Item(1) returns the upper-left cell in the range; NamedRange.Item(2) returns the cell immediately to the right of the upper-left cell.

ColumnIndex

A number or string that indicates the column number of the cell you want to access, starting with either 1 or "A" for the first column in the range.

If you attempt to use Item without specifying any parameters, Item will get a NamedRange_ItemType object that is part of the Visual Studio infrastructure and is not intended to be used directly from your code.

The RowIndex and ColumnIndex arguments are relative offsets. In other words, specifying a RowIndex of 1 returns cells in the first row of the range, not the first row of the worksheet.

The following code example creates a NamedRange and then uses the Item property to select the cell that is offset from the NamedRange by three columns and three rows.

This version is for a document-level customization.

Microsoft.Office.Tools.Excel.NamedRange itemRange;
private void SelectItem()
{
    itemRange = this.Controls.AddNamedRange(
        this.Range["A1"], "itemRange");
    itemRange.Value2 = "NamedRange";
    Excel.Range offsetCell =
        (Excel.Range)this.itemRange.Item[3, 3];
    offsetCell.Value2 = "Offset cell.";
    offsetCell.Select();
}

This version is for an application-level add-in.

Return to top
Show: