I'm working on an automation of my Excel file by using VBA. I'm not experienced at all, but I'm learning OTJ.
We have a file containing a PivotTable which has been converted to OLAP Cubes. We use 35 slicers (with two options, only one of which is needed) on the worksheet to have information about different stores. My goal is to automate the process of manual clicking on the slicer we need, waiting for it to finish calculating, converting the Excel sheet to a PDF, clearing the filter and go on to the next (for 35 times).
I recorded my manual selection and clearing of one slicer:
The Array part is messing with me to know how to proceed..
I want to loop through all 35 slicers, but only for one item, and have that Array part filled accordingly (changes to that line).
I've found a couple of threads here and on stackoverflow, but I'm not getting there.
And I'm missing the looping part for all slicers and setting the correct item for the selected slicer...
Anyone can guide me?
We have a file containing a PivotTable which has been converted to OLAP Cubes. We use 35 slicers (with two options, only one of which is needed) on the worksheet to have information about different stores. My goal is to automate the process of manual clicking on the slicer we need, waiting for it to finish calculating, converting the Excel sheet to a PDF, clearing the filter and go on to the next (for 35 times).
I recorded my manual selection and clearing of one slicer:
VBA Code:
ThisWorkbook.SlicerCaches("Slicer_All").VisibleSlicerItemsList = Array("[FiliaalOmzet].[All].&[All]")
ThisWorkbook.SlicerCaches("Slicer_All").ClearManualFilter
The Array part is messing with me to know how to proceed..
I want to loop through all 35 slicers, but only for one item, and have that Array part filled accordingly (changes to that line).
I've found a couple of threads here and on stackoverflow, but I'm not getting there.
VBA Code:
Sub slicerArray()
Dim slArray as Variant ' to store the Slicer names in an Array
slArray = Array("Slicer_All","Slicer_AllExSoi") 'need 33 more added, but I want to test this with these first
For each slName in slArray
Call slicers(slName)
next slName
End Sub
Sub slicers(slName As Variant)
Dim slItem As SlicerItem, slDummy As SlicerItem
Dim slCache As SlicerCache
Dim sl As Slicer
Dim slItemsArray() as Variant ' store values for matching SlicerItems in an Array
Dim slItemsString As String
slItemsString = "[FiliaalOmzet].[All].&[All];|;[FiliaalOmzet].[AllExSoi].&[AllExSoi]" ' I need 33 more selections, want to test these two first
slItemsArray = Split(slItemsString, ";|")
Set wb = ThisWorkbook
Set slCache = wb.SlicerCaches(slName)
End Sub
And I'm missing the looping part for all slicers and setting the correct item for the selected slicer...
Anyone can guide me?