Class SlicerItem (Excel VBA)

The class SlicerItem represents an item in a slicer.

Item

To use a SlicerItem class variable it first needs to be instantiated, for example

Dim slcite as SlicerItem
Set slcite = ActiveWorkbook.ActiveSlicer.ActiveItem

The following procedures can be used to set variables of type SlicerItem: Slicer.ActiveItem and SlicerItems.Item.

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

SlicerItems.Count

Returns the number of objects in the collection.

Dim lngCount As Long
lngCount = ActiveWorkbook.SlicerCaches(1).SlicerItems.Count

SlicerItems.Item

Returns a SlicerItem object from a collection.

Item (Index)

Index: The name or index number of the SlicerItem object.

Dim slciteItem As SlicerItem
Set slciteItem = ActiveWorkbook.SlicerCaches(1).SlicerItems(Index:=1)