다음을 통해 공유


WorksheetBase.PivotTables(Object) Method

Definition

Gets an object that represents either a single PivotTable report (a PivotTable object) or a collection of all the PivotTable reports (a PivotTables object) on a worksheet.

public object PivotTables (object index);
member this.PivotTables : obj -> obj
Public Function PivotTables (Optional index As Object) As Object

Parameters

index
Object

The name or number of the report.

Returns

An object that represents either a single PivotTable report (a PivotTable object) or a collection of all the PivotTable reports (a PivotTables object) on a worksheet.

Examples

The following code example uses the PivotTables method to get the Microsoft.Office.Interop.Excel.PivotTables collection of the current worksheet and refreshes each PivotTable in the collection

This example is for a document-level customization.

private void RefreshPivotTables()
{
    Excel.PivotTables pivotTables1 = 
        (Excel.PivotTables)this.PivotTables();

    if (pivotTables1.Count > 0)
    {
        foreach (Microsoft.Office.Interop.Excel.PivotTable table
             in pivotTables1)
        {
            table.RefreshTable();
        }
    }
    else
    {
        MessageBox.Show("This workbook contains no pivot tables.");
    }
}
Private Sub RefreshPivotTables()
    Dim pivotTables1 As Excel.PivotTables = _
        CType(Me.PivotTables(), Excel.PivotTables)

    If pivotTables1.Count > 0 Then
        For Each table As Microsoft.Office.Interop.Excel.PivotTable _
              In pivotTables1
            table.RefreshTable()
        Next
    Else
        MsgBox("This workbook contains no pivot tables.")
    End If
End Sub

Remarks

Optional Parameters

For information on optional parameters, see Optional Parameters in Office Solutions.

Applies to