I recorded a macro to set the value of a Pivot Table Page Filter. I copied that macro code to an existing function that refreshes all pivot tables in the workbook. When I run the code in Excel, it works perfectly. When I invoke the refresh function from a VBScript, it works perfectly. When I invoke the refresh function with the additional ActiveSheet lines coded below, I get a 1004 error.
New macro code now results in a 1004 error. When I comment out the last two lines, the refresh function works perfectly.
Sheets("Sheet1").Select
ActiveSheet.PivotTables("PivotTable1").PivotFields("Day").ClearAllFilters <--- ERROR 1004 occurs here
ActiveSheet.PivotTables("PivotTable1").PivotFields("Day").CurrentPage = "4"
When I get this working, I want to set the value of CurrentPage to the day value of today. So, if today is 3/6/2015, I would want the page filter to be 6.
Thanks in advance
I attached the SampleTemplate.xlsm and the Refresh.txt. The Refresh is really a VBS file and should be changed to that extension. This is bare bones, just to demonstrate the concept.
Bookmarks