Loop through slicer and save to PDF

vedderman

New Member
Joined
Nov 2, 2016
Messages
27
This has been asked here and other sites, but for the life of me I can't figure out how to get it to work. I have a workbook built in Powerpivot. First sheet is a bunch of slicers for province, city, area, region, division. I want to loop through the divisions and save the second and third sheets in my book as a PDF. Code below seems simple enough, but errors at the Each sI In sC.SlicerItem part.

Code:
Sub PrintToPDF()

Dim sI As SlicerItem, sI2 As SlicerItem, sC As SlicerCache


Set sC = ActiveWorkbook.SlicerCaches("Slicer_Profit_Centre_Level_8_Descripton") 'not a spelling error'


With sC


    For Each sI In sC.SlicerItem


        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 = "I:\Accounting\Data\Margin Delta\"
    FName = "&sI.Name"
        
       ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, Filename:= _
        "FPath & " \ " & FName & .pdf", Quality:=xlQualityStandard, _
        IncludeDocProperties:=True, IgnorePrintAreas:=False, OpenAfterPublish:= _
        False
   Next
   End With
   


End Sub

Any help would be appreciated. Tried recording the steps but it didn't really help me decipher my issue.
 

Excel Facts

Create a Pivot Table on a Map
If your data has zip codes, postal codes, or city names, select the data and use Insert, 3D Map. (Found to right of chart icons).

Forum statistics

Threads
1,223,246
Messages
6,170,999
Members
452,373
Latest member
TimReeks

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top