Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.

Reply
Anonymous
Not applicable

Excel - Power Query: VBA for looping through slicers created using data model. Help!

All - this is in RE: Excel VBA. I am looking for looping through slicer selection and print PDF's. my code does work for standard pivots, but it does not work when using it on PowerPivot which is what I am looking for.

Can anyone please shed some light on how to turn the below so it works in powerpivot? (slicer from power pivot source data)

 

Let me know any questions - looking forward to hearing any tips 🙂 🙂

 

Thanks! 🙂

 

 

 

 

Option Explicit

Sub ExportPDFs()

Dim sI As SlicerItem, sI2 As SlicerItem, sc As SlicerCacheDim fname$

Set sc = ActiveWorkbook.SlicerCaches("Slicer_Date")

With sc

    For Each sI In sc.SlicerItems
        If sI.HasData = True Then        sc.ClearManualFilter

        For Each sI2 In sc.SlicerItems
            If sI.Name = sI2.Name Then sI2.Selected = True Else: sI2.Selected = False
        Next        Debug.Print sI.Name
        fname = sI.Caption & " " & Format(Date, "MM-DD-YYYY") & " " & "Report"        ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, Filename:=fname, _
        Quality:=xlQualityStandard, IncludeDocProperties:=True, IgnorePrintAreas:=False, OpenAfterPublish:=False
        End If
    Next    ActiveWorkbook.SlicerCaches("Slicer_Year").ClearManualFilter
    MsgBox "Reports Saved"
End With
End Sub
1 REPLY 1
v-juanli-msft
Community Support
Community Support

Hi @Anonymous 

As tested, i'm afriad it doesn't support to loop slicer and export to pdf programmatically currently.

There is a custom visual which works like a dynamic slicer and animates your other power bi visuals without any user interaction.

http://blog.pragmaticworks.com/power-bi-custom-visuals-play-axis

 

Best Regards
Maggie

 

Community Support Team _ Maggie Li
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Helpful resources

Announcements
July 2025 community update carousel

Fabric Community Update - July 2025

Find out what's new and trending in the Fabric community.

July PBI25 Carousel

Power BI Monthly Update - July 2025

Check out the July 2025 Power BI update to learn about new features.