I have Win10 and Excel 2016. This is is really perplexing to me. I have a number of Slicers in an Excel workbook file. In my test code, all I wanted to do are (1) Get a count of the Slicer items in the Slicer, but I got a
Run-time error '1004' Application-defined or object-defined error:
Debug.Print ActiveWorkbook.SlicerCaches("Slicer_BusinessDivision").SlicerItems.count
(2) I want to list out all the Slicer items using the below code, in this case also got the '1004' error:
Dim oSlicerItem As slicerItem
For Each oSlicerItem In ActiveWorkbook.SlicerCaches("Slicer_BusinessDivision").SlicerItems
Debug.Print oSlicerItem.Value
Next
According to the MS documentation, SlicerItems
property is contained in a SlicerCache
object in:
https://docs.microsoft.com/en-us/office/vba/api/excel.sliceritems
which is what I specified and also Intellisense showed it as well. Interesting, when I Dim
the object variable as above, Excel turn As SlicerItem
to the lower case As slicerItem
. Can you share your thoughts. I have been looking at the MS documentation and I don't know what I am doing wrong.
From: Dim oSlicerItem As SlicerItem
To: Dim oSlicerItem As slicerItem
After making adjustment based on BigBen and Tim's comment, I looked at the documentation, which said:
https://docs.microsoft.com/en-us/office/vba/api/excel.slicercachelevel
"Use the SlicerCacheLevels collection of the parent SlicerCache object to access the SlicerCacheLevel objects that represent these hierarchy levels."
Properties
- Application
- Count
- Creator
- CrossFilterType
- Name
- Ordinal
- Parent
- SlicerItems
- SortItems
- VisibleSlicerItemsList
which contains the SlicerItems collection, but not sure how I can access this. I tried using:
Dim cache As SlicerCache
Set cache = ActiveWorkbook.SlicerCaches("Slicer_BusinessDivision")
Debug.Print cache.OLAP = True '//this is true
Debug.Print cache.SlicerCacheLevels.Parent
But Intellisense does not show anything else beyond ".Parent", any ideas?
Thanks in advance,
G.
DIm cache As SlicerCache
,Set cache = ActiveWorkbook.SlicerCaches("Slicer_BusinessDivision")
. If that succeeds, then the issue is withSlicerItems
. – BigBen