Share via


Worksheet.Index Property (2007 System)

Gets the index number of the worksheet within the collection of worksheets.

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

Syntax

'Declaration
Public ReadOnly Property Index As Integer
'Usage
Dim instance As Worksheet 
Dim value As Integer 

value = instance.Index
public int Index { get; }
public:
property int Index {
    int get ();
}
public function get Index () : int

Property Value

Type: System.Int32
The index number of the worksheet within the collection of worksheets.

Examples

The following code example uses the Index property to display the index number of the current worksheet before and after moving the worksheet to the last position in the workbook by using the Move method.

This example is for a document-level customization.

Private Sub DisplayIndex()
    MsgBox("Before moving, this worksheet is at tab number " & _
        Me.Index.ToString())

    ' Move the worksheet to the last position in the workbook. 
    Me.Move(After:=Globals.ThisWorkbook.Worksheets( _
        Globals.ThisWorkbook.Worksheets.Count))

    MsgBox("After moving, this worksheet is at tab number " & _
        Me.Index.ToString())
End Sub
private void DisplayIndex()
{
    MessageBox.Show("Before moving, this worksheet is at tab number " +
        this.Index.ToString());

    // Move the worksheet to the last position in the workbook. 
    this.Move(missing, 
        Globals.ThisWorkbook.Worksheets[Globals.ThisWorkbook.Worksheets.Count]);

    MessageBox.Show("After moving, this worksheet is at tab number " +
        this.Index.ToString());
}

.NET Framework Security

See Also

Reference

Worksheet Class

Worksheet Members

Microsoft.Office.Tools.Excel Namespace