Hi
I am trying to write a VBA that will take my sheet through each slicer option and print each country to an individual PDF. The first part seems to work (and go through each slicer option) but I am struggling to get it to save to PDF with the variable file name.
Any help would be really useful. Thanks in advance.
Here is the code I am using currently:
Sub PrintAllCountriesToPDF()
Dim sI As SlicerItem, sI2 As SlicerItem, sC As SlicerCache
Set sC = ActiveWorkbook.SlicerCaches("Slicer_Country")
With sC
For Each sI In sC.SlicerItems
sC.ClearManualFilter
For Each sI2 In sC.SlicerItems
If sI.Name = sI2.Name Then sI2.Selected = True Else: sI2.Selected = False
Next
Dim FName As String
Dim FPath As String
FPath = "C:\Users\kalexa03\Documents\CaratDashboardTest\"
FName = "&sI.Name"
ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, Filename:= _
"FPath & " \ " & FName & .pdf", Quality:=xlQualityStandard, _
IncludeDocProperties:=True, IgnorePrintAreas:=False, OpenAfterPublish:= _
False
Next
End With
End Sub
Bookmarks