Share via


WorksheetBase.Previous Property

Gets a Microsoft.Office.Interop.Excel.Worksheet that represents the previous sheet.

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

Syntax

'Declaration
Public ReadOnly Property Previous As Object
public Object Previous { get; }

Property Value

Type: System.Object
A Microsoft.Office.Interop.Excel.Worksheet that represents the previous sheet; nulla null reference (Nothing in Visual Basic) if the current worksheet is the first sheet in the workbook.

Examples

The following code example uses the Previous property to determine whether the current WorksheetBase is the first sheet in the workbook. If the current WorksheetBase is not the first sheet, then the name of the previous sheet is displayed.

This example is for a document-level customization.

Private Sub DisplayPrevious()
    If Not (Me.Previous Is Nothing) Then 
        Dim sheet As Excel.Worksheet = _
            CType(Me.Previous, Excel.Worksheet)
        MsgBox("The previous worksheet is " & sheet.Name)
    Else
        MsgBox("The current worksheet is the first worksheet.")
    End If 
End Sub
private void DisplayPrevious()
{
    if (this.Previous != null)
    {
        Excel.Worksheet sheet = (Excel.Worksheet)this.Previous;
        MessageBox.Show("The previous worksheet is " + sheet.Name);
    }
    else
    {
        MessageBox.Show("The current worksheet is the first worksheet.");
    }
}

.NET Framework Security

See Also

Reference

WorksheetBase Class

Microsoft.Office.Tools.Excel Namespace