I have a workbook containing OLAP Pivot Tables. It needs to be updated on a monthly basis, so I want to build a macro that adds the previous month to one of the filters on a table. When filtered correctly There will be a few dozen items selected in the filter for this field and 3 or 4 items unselected in the filter. The number of items (months) selected increases by one each month.
The problem is that I keep getting error messages for everything I try. None of the Pivot Field Object Members I try seem to work...
AddPageItem:
ActiveSheet.PivotTables("PivotTable3").PivotFields("[Client].[Month Converted].[Month Converted]").AddPageItem ("[Client].[Month Converted].&[2014/01]")
Visible:
ActiveSheet.PivotTables("PivotTable3").PivotFields("[Client].[Month Converted].[Month Converted]").PivotItems("[Client].[Month Converted].&[2012/11]").Visible = False
PivotFilters:
ActiveSheet.PivotTables("PivotTable3").PivotFields("[Client].[Month Converted].[Month Converted]").PivotFilters.Add Type:= _
xlCaptionIsLessThanOrEqualTo, Value1:="2014/01"
All of these yield errors, usually "Application-Defined or Object-Defined error". Sometimes "Unable to get the Pivot Items property of the Pivot Field class".
The only thing that works is VisibleItemsList:
ActiveSheet.PivotTables("PivotTable3").PivotFields("[Client].[Month Converted].[Month Converted]").VisibleItemsList = Array("[Client].[Month Converted].&[2014/01]")
Unfortunately, that would require me to enter all of the selected months each time. Since the list is 30+ months long and will increase by 1 every month ad infinitum that is a bit impractical.
Why are none of the other Object Members working? I am open to any suggestion that will let me easily do what I'm trying to do...
I appreciate your help.
The problem is that I keep getting error messages for everything I try. None of the Pivot Field Object Members I try seem to work...
AddPageItem:
ActiveSheet.PivotTables("PivotTable3").PivotFields("[Client].[Month Converted].[Month Converted]").AddPageItem ("[Client].[Month Converted].&[2014/01]")
Visible:
ActiveSheet.PivotTables("PivotTable3").PivotFields("[Client].[Month Converted].[Month Converted]").PivotItems("[Client].[Month Converted].&[2012/11]").Visible = False
PivotFilters:
ActiveSheet.PivotTables("PivotTable3").PivotFields("[Client].[Month Converted].[Month Converted]").PivotFilters.Add Type:= _
xlCaptionIsLessThanOrEqualTo, Value1:="2014/01"
All of these yield errors, usually "Application-Defined or Object-Defined error". Sometimes "Unable to get the Pivot Items property of the Pivot Field class".
The only thing that works is VisibleItemsList:
ActiveSheet.PivotTables("PivotTable3").PivotFields("[Client].[Month Converted].[Month Converted]").VisibleItemsList = Array("[Client].[Month Converted].&[2014/01]")
Unfortunately, that would require me to enter all of the selected months each time. Since the list is 30+ months long and will increase by 1 every month ad infinitum that is a bit impractical.
Why are none of the other Object Members working? I am open to any suggestion that will let me easily do what I'm trying to do...
I appreciate your help.