Class SlicerItem (Excel VBA)
The class SlicerItem represents an item in a slicer. To use a SlicerItem class variable it first needs to be instantiated, for example
Dim slcite as SlicerItem
Set slcite = ActiveWorkbook.ActiveSlicer.ActiveItem
For Each
Here is an example of processing the SlicerItem items in a collection.
Dim slcite As SlicerItem
For Each slcite In ActiveWorkbook.SlicerItems
Next slcite
Caption
Returns the label text for the slicer item.
Dim strCaption As String
strCaption = ActiveWorkbook.ActiveSlicer.ActiveItem.Caption
HasData
Returns whether the slicer item contains data that matches the current manual filter state.
True if the slicer item contains data that matches the current manual filter state; otherwise, False. This property is only supported when cross filtering is turned on, and will generate a run-time error otherwise. To determine if cross filtering is turned on for a slicer associated with a PivotTable report, check the value of the CrossFilterType property of the specified SlicerItem object's parent SlicerCache object. To determine if cross filtering is turned on for a slicer associated with an OLAP data source, check the value of the CrossFilterType property of the SlicerCacheLevel object that corresponds to the OLAP hierarchy being filtered.
Dim booHasData As Boolean
booHasData = ActiveWorkbook.ActiveSlicer.ActiveItem.HasData
Name
Returns the name of the slicer item.
Dim strName As String
strName = ActiveWorkbook.ActiveSlicer.ActiveItem.Name
Selected
Returns or sets whether the slicer item is selected. Read/write for slicers connected to non-OLAP data sources.
True if the slicer item is selected; otherwise, False.
ActiveWorkbook.ActiveSlicer.ActiveItem.Selected = True
SourceName
Returns the source name of the slicer item.
Dim strSourceName As String
strSourceName = ActiveWorkbook.ActiveSlicer.ActiveItem.SourceName
SourceNameStandard
Returns the slicer item's source name in standard English (United States) format settings.
This property is used when a slicer item has a localized version and its SourceNameStandard property value differs from the SourceName property value, such as with date formatting.
Dim strSourceNameStandard As String
strSourceNameStandard = ActiveWorkbook.ActiveSlicer.ActiveItem.SourceNameStandard
Value
Returns the value of the slicer item.
Dim strValue As String
strValue = ActiveWorkbook.ActiveSlicer.ActiveItem.Value