Name
pivottables.Add(PivotCache, TableDestination, [TableName], [ReadData], [DefaultVersion])
Synopsis
Creates a new pivot table from an existing pivot cache and returns the created PivotTable object.
|
Argument |
Settings |
|---|---|
|
|
The |
|
|
The |
|
|
A name to assign to the pivot table. Default is |
|
|
For database queries, True reads all of the fields from the data source; False delays retrieving the data until the pivot cache is refreshed. Default is True. |
|
|
The Excel version assigned to pivot table. Can be |
This method is equivalent to the PivotCache object’s CreatePivotTable method. The following code creates a pivot cache from a database query and then uses that pivot cache to create a pivot table:
Sub CreateSalesThisWeekPT( ) Dim pc As PivotCache, pt As PivotTable, pf As PivotField, _ ws As Worksheet ' Create a new pivot cache for database query. Set pc = ActiveWorkbook.PivotCaches.Add(xlExternal) ' Create a connection string and SQL query. pc.Connection = "ODBC;DRIVER=SQL Server;SERVER=USERS;" & _ "UID=jeff;APP=Microsoft Office 2003;WSID=WOMBAT4;" & _ "DATABASE=Sales;Trusted_Connection=True" pc.CommandType = xlCmdSql pc.CommandText = "SELECT SalesRank, ProductName, Date FROM Amazon " & ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access