共用方式為


WorksheetBase.Parent Property

Gets the parent object for the worksheet.

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 Parent As Object
public Object Parent { get; }

Property Value

Type: System.Object
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 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
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.");
    }
}

.NET Framework Security

See Also

Reference

WorksheetBase Class

Microsoft.Office.Tools.Excel Namespace