WorksheetBase.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.v4.0.Utilities (in Microsoft.Office.Tools.Excel.v4.0.Utilities.dll)
Syntax
'Declaration
Public Function PivotTables ( _
index As Object _
) As Object
public Object PivotTables(
Object index
)
Parameters
- index
Type: System.Object
The name or number of the report.
Return Value
Type: System.Object
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.
Remarks
Optional Parameters
For information on optional parameters, see Optional Parameters in Office Solutions.
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 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
private void RefreshPivotTables()
{
Excel.PivotTables pivotTables1 =
(Excel.PivotTables)this.PivotTables(missing);
if (pivotTables1.Count > 0)
{
foreach (Microsoft.Office.Interop.Excel.PivotTable table
in pivotTables1)
{
table.RefreshTable();
}
}
else
{
MessageBox.Show("This workbook contains no pivot tables.");
}
}
.NET Framework Security
- Full trust for the immediate caller. This member cannot be used by partially trusted code. For more information, see Using Libraries from Partially Trusted Code.