VBA code to loop through a slicer printing each slicer item

Use this forum for any general discussion and questions about Excel
Frank
Posts: 28
Joined: Wed Jul 13, 2016 8:31 am

VBA code to loop through a slicer printing each slicer item

Postby Frank » Thu Apr 13, 2017 10:40 am

I have been trying to write a VBA code to loop through a slicer but keep hetting 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

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

Return to “Excel”

Who is online

Users browsing this forum: No registered users and 1 guest