vba loop through pivots

spinkung

Registered User.
Local time
Today, 17:15
Joined
Dec 4, 2006
Messages
267
Hi All,

I'm trying to loop through some pivots in excel from access vba.

the top refresh of my code works (if i hardcode in the pivot name)
the second refresh gives an error (passing the pivot name into a variable)

Code:
Dim pvt As PivotTable
For Each pvt In xlSht2.PivotTables
xlSht2.PivotTables("PivotTable1").PivotCache.Refresh
xlSht2.PivotTables(pvt).PivotCache.Refresh
Next

the error:
unable to get the pivot tables property of the worksheet class

Anyone??

Thanks,
Spin
 
Try:

Code:
Dim pvt As PivotTable
For Each pvt In xlSht2.PivotTables
xlSht2.PivotTables("PivotTable1").PivotCache.Refresh
xlSht2.PivotTables(pvt.name).PivotCache.Refresh
Next

Or:


Code:
Dim pvt As PivotTable
For Each pvt In xlSht2.PivotTables
   pvt.PivotCache.Refresh
Next
 
thanks chergh, second way worked a treat.
 

Users who are viewing this thread

Back
Top Bottom