tmoreira001
New Member
- Joined
- Jan 18, 2022
- Messages
- 1
- Office Version
- 2021
- Platform
- Windows
Hi, I am using the below VBA to export to pdf based on a slicer. The main problem is that it is selecting those slicers that are not visible (no data). How can I have a loop with only visible slicers? HELP PLEASE!
VBA Code:
Sub Reporte()
Dim sC As SlicerCache
Set sC = ActiveWorkbook.SlicerCaches("Slicer_X")
For i = 1 To sC.SlicerItems.Count
sC.SlicerItems(i).Selected = True
If i <> 1 Then sC.SlicerItems(i - 1).Selected = False
ActiveSheet.Range("AA2") = sC.SlicerItems(i).Name
ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, Filename:= _
"C:\Users\X\Desktop\" & "Reporte" & Range("AA2").Text & ".pdf", Quality:= _
xlQualityHigh, IncludeDocProperties:=True, IgnorePrintAreas:=False, _
OpenAfterPublish:=False
Next
End Sub