Class Slicers (Excel VBA)
A collection of Slicer objects. To use a Slicers class variable it first needs to be instantiated, for example
Dim slcs as Slicers
Set slcs = ActiveCell.PivotTable.Slicers
For Each
Here is an example of processing the Slicers items in a collection.
Dim slc As Slicer
For Each slc In Application.Slicers
Next slc
Add
Creates a new slicer and returns a Slicer object.
Add (SlicerDestination, Level, Name, Caption, Top, Left, Width, Height)
Sub CreateNewSlicer()
ActiveWorkbook.SlicerCaches.Add("Adventure Works", _
"[Customer].[Customer Geography]").Slicers.Add ActiveSheet, _
"[Customer].[Customer Geography].[Country]", "Country 1", "Country", _
252, 522, 144, 216)
End Sub
Arguments
The following argument is required
SlicerDestination (Worksheet) - A String that specifies the name of the sheet, or a Worksheet object that represents the sheet, where the resulting slicer will be placed. The destination sheet must be in the workbook that contains the Slicers object specified by expression.
Optional arguments
The following arguments are optional
Level (Long,String) - For OLAP data sources, the ordinal or the Multidimensional Expression (MDX) name of the level on which the slicer creation is based. Not supported for non-OLAP data sources.
Name (String) - The name of the slicer. Excel automatically generates a name if one is not specified. The name must be unique across all slicers within a workbook.
Caption (String) - The caption of the slicer.
Top (Points) - The initial vertical position of the slicer, in points, relative to the upper-left corner of cell A1 on a worksheet.
Left - The initial horizontal position of the slicer, in points, relative to the upper-left corner of cell A1 on a worksheet
Width - The initial width, in points, of the slicer control
Height (Long) - The initial height, in points, of the slicer control.
Count
Returns the number of objects in the collection.
Dim lngCount As Long
lngCount = ActiveCell.PivotTable.Slicers.Count
Item
Returns a Slicer object from the collection.
Item (Index)
Index: The name or index number of the Slicer object.
Dim slcItem As Slicer
Set slcItem = ActiveCell.PivotTable.Slicers(Index:=1)