Udostępnij za pośrednictwem


NamedRange.Item Property (2007 System)

Gets a Range that represents a range at an offset to the NamedRange control.

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

Syntax

'Declaration
<BrowsableAttribute(False)> _
Public ReadOnly Property Item As NamedRange._ItemType
'Usage
Dim instance As NamedRange 
Dim value As NamedRange._ItemType 

value = instance.Item
[BrowsableAttribute(false)]
public NamedRange._ItemType Item { get; }
[BrowsableAttribute(false)]
public:
property NamedRange._ItemType^ Item {
    NamedRange._ItemType^ get ();
}
public function get Item () : NamedRange._ItemType

Property Value

Type: Microsoft.Office.Tools.Excel.NamedRange._ItemType
A Range that represents a range at an offset to the NamedRange control.

Remarks

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 Tools for Office 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.

Examples

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.

Private itemRange As Microsoft.Office.Tools.Excel.NamedRange

Private Sub SelectItem()
    itemRange = Me.Controls.AddNamedRange( _
        Me.Range("A1"), "itemRange")
    itemRange.Value2 = "NamedRange" 
    Dim offsetCell As Excel.Range = _
        CType(Me.itemRange.Item(3, 3), Excel.Range)
    offsetCell.Value2 = "Offset cell."
    offsetCell.Select()
End Sub
Microsoft.Office.Tools.Excel.NamedRange itemRange;
private void SelectItem()
{
    itemRange = this.Controls.AddNamedRange(
        this.Range["A1", missing], "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.

Private itemRange As NamedRange

Private Sub SelectItem()
    Dim vstoWorksheet As Worksheet = CType( _
        Me.Application.ActiveWorkbook.Worksheets(1),  _
        Excel.Worksheet).GetVstoObject()
    itemRange = vstoWorksheet.Controls.AddNamedRange( _
        vstoWorksheet.Range("A1"), "itemRange")
    itemRange.Value2 = "NamedRange" 
    Dim offsetCell As Excel.Range = _
        CType(Me.itemRange.Item(3, 3), Excel.Range)
    offsetCell.Value2 = "Offset cell."
    offsetCell.Select()
End Sub
NamedRange itemRange;
private void SelectItem()
{
    Worksheet vstoWorksheet = ((Excel.Worksheet)
        this.Application.ActiveWorkbook.Worksheets[1]).GetVstoObject();
    itemRange = vstoWorksheet.Controls.AddNamedRange(
        vstoWorksheet.Range["A1", missing], "itemRange");
    itemRange.Value2 = "NamedRange";
    Excel.Range offsetCell =
        (Excel.Range)itemRange.Item[3, 3];
    offsetCell.Value2 = "Offset cell.";
    offsetCell.Select();
}

.NET Framework Security

See Also

Reference

NamedRange Class

NamedRange Members

Microsoft.Office.Tools.Excel Namespace

Change History

Date

History

Reason

July 2008

Added a version of the code example for an application-level add-in.

SP1 feature change.