I'm trying to write some VBA code to count all available items in a slicer that is connected to an ODBC connection. Below is what I currently have but the result is always 1 when I'm expecting 8 as there are 8 available items to choose from in the slicer. Any ideas?
Public Function GetSlicerItemsCount(SlicerName As String) As IntegerDim oSc As SlicerCache
Dim oSi As SlicerItem
Dim lCt As Integer
On Error Resume Next
Application.Volatile
Set oSc = ThisWorkbook.SlicerCaches(SlicerName)
If Not oSc Is Nothing Then
For Each oSi In oSc.SlicerItems
lCt = lCt + 1
Next
GetSlicerItemsCount = lCt
Else
GetSlicerItemsCount = 0
End If
End Function