Export (0) Print
Expand All

Worksheet.PivotTables Method

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

Namespace: Microsoft.Office.Tools.Excel
Assembly: Microsoft.Office.Tools.Excel (in microsoft.office.tools.excel.dll)

public virtual Object PivotTables (
	[OptionalAttribute] Object Index
)

Parameters

Index

The name or number of the report.

Return Value

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

Optional Parameters

For information on optional parameters, see Understanding Optional Parameters in COM Interop.

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

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

    if (pivotTables1.Count > 0)
    {
        for (int i = 0; i <= pivotTables1.Count; i++)
        {
            pivotTables1.Item(i).RefreshTable();
        }
    }
    else
    {
        MessageBox.Show("This workbook contains no pivot tables.");
    }
}

Show:
© 2015 Microsoft