WorksheetBase.Parent Property

Definition

Gets the parent object for the worksheet.

public:
 property System::Object ^ Parent { System::Object ^ get(); };
public object Parent { get; }
member this.Parent : obj
Public ReadOnly Property Parent As Object

Property Value

The parent object for the worksheet.

Examples

The following code example uses the Parent property to determine whether the current WorksheetBase has a parent. If the current WorksheetBase has a parent, then name of the parent workbook is displayed.

This example is for a document-level customization.

private void DisplayParent()
{
    if (this.Parent != null)
    {
        Excel.Workbook book = (Excel.Workbook)this.Parent;
        MessageBox.Show("The parent workbook for this worksheet is: " + 
            book.Name);
    }
    else
    {
        MessageBox.Show("This worksheet has no parent.");
    }
}
Private Sub DisplayParent()
    If Not (Me.Parent Is Nothing) Then
        Dim book As Excel.Workbook = _
            CType(Me.Parent, Excel.Workbook)
        MsgBox("The parent workbook for this worksheet is: " & _
            book.Name)
    Else
        MsgBox("This worksheet has no parent.")
    End If
End Sub

Applies to