I have been trying to write a VBA code to loop through a slicer but keep getting an error "1004 Application-defined or object-defined error". I can get the print to PDF working, but unable to loop. below is my code. Appreciate any help.. thanks.
Code:
Sub Step_Thru_SlicerItems2()
Dim slItem As SlicerItem
Dim i As Long
Application.ScreenUpdating = False
With ActiveWorkbook.SlicerCaches("Slicer_Shareholder_Name2")
'--deselect all items except the first
.SlicerItems(1).Selected = True
For Each slItem In .VisibleSlicerItems
If slItem.Name <> .SlicerItems(1).Name Then _
slItem.Selected = False
Next slItem
Call Saveaspdf
'--step through each item and run custom function
For i = 2 To .SlicerItems.Count
.SlicerItems(i).Selected = True
.SlicerItems(i - 1).Selected = False
Call Saveaspdf
Next i
End With
Application.ScreenUpdating = True
End Sub