S
Scott
I was hoping someone could help me with updating pivot tables in VBA.
Currently I have a workbook with 10 pivot tables in it. I have
another file that calculates a bunch of data. Then, using VBA, I
create a new sheet in the Pivot Table workbook that contains the flat
file. I then loop through all the pivot tables and use
PivotCache.Create for each pivot basing the cache on the flat file
data.
-------------------------------------------------------------------------------------------------------------------
The code is as follows:
' Update all of the pivot tables with the new flat file data
For Each ws In outputWB.Worksheets
For Each pt In ws.PivotTables
pt.ChangePivotCache
outputWB.PivotCaches.Create(xlDatabase, pivotSheet.Range(Cells(1, 1),
pivotSheet.Cells(pivotEndRow, pivotEndCol)))
pt.RefreshTable
pt.SaveData = True
Next pt
Next ws
-------------------------------------------------------------------------------------------------------------------
This makes the file size very large. What I would like to do is
create a single Pivot Cache, and then loop through each of the pivot
tables and update their cacheindex to equal the cache I created. I
can't seem to get this to work.
I would like to do something like:
-------------------------------------------------------------------------------------------------------------------
Dim pc as PivotCache
set pc = outputWB.PivotCaches.Create(xlDatabase,
pivotSheet.Range(Cells(1, 1), pivotSheet.Cells(pivotEndRow,
pivotEndCol)))
For Each ws In outputWB.Worksheets
For Each pt In ws.PivotTables
pt.CacheIndex = pc.index
pt.RefreshTable
pt.SaveData = True
Next pt
Next ws
-------------------------------------------------------------------------------------------------------------------
Does anybody have any suggestions as to how to modify the code such
that I am able to create a single PivotCache and have each of the
pivot tables use that single pivot cache?
Thanks!
Currently I have a workbook with 10 pivot tables in it. I have
another file that calculates a bunch of data. Then, using VBA, I
create a new sheet in the Pivot Table workbook that contains the flat
file. I then loop through all the pivot tables and use
PivotCache.Create for each pivot basing the cache on the flat file
data.
-------------------------------------------------------------------------------------------------------------------
The code is as follows:
' Update all of the pivot tables with the new flat file data
For Each ws In outputWB.Worksheets
For Each pt In ws.PivotTables
pt.ChangePivotCache
outputWB.PivotCaches.Create(xlDatabase, pivotSheet.Range(Cells(1, 1),
pivotSheet.Cells(pivotEndRow, pivotEndCol)))
pt.RefreshTable
pt.SaveData = True
Next pt
Next ws
-------------------------------------------------------------------------------------------------------------------
This makes the file size very large. What I would like to do is
create a single Pivot Cache, and then loop through each of the pivot
tables and update their cacheindex to equal the cache I created. I
can't seem to get this to work.
I would like to do something like:
-------------------------------------------------------------------------------------------------------------------
Dim pc as PivotCache
set pc = outputWB.PivotCaches.Create(xlDatabase,
pivotSheet.Range(Cells(1, 1), pivotSheet.Cells(pivotEndRow,
pivotEndCol)))
For Each ws In outputWB.Worksheets
For Each pt In ws.PivotTables
pt.CacheIndex = pc.index
pt.RefreshTable
pt.SaveData = True
Next pt
Next ws
-------------------------------------------------------------------------------------------------------------------
Does anybody have any suggestions as to how to modify the code such
that I am able to create a single PivotCache and have each of the
pivot tables use that single pivot cache?
Thanks!