Cycle Through Pivot Filter and Print to PDF

DPhilip

New Member
Joined
Jan 12, 2016
Messages
27
Hi Guys,

I have a VBA code that cycles through my pivot filter and prints the file to PDF. It filters the vendor number and I print a summary for each vendor. The problem is one vendor has 4 different summaries and each pivot is on a different worksheet. When I run the below Macro, it saves 4 files in 4 separate folders. I wanted to merge them so I send one PDF with 4 pages vs. 4 PDFS with single pages.

I really appreciate any help I can get.

Thanks in advance.
Dennis
VBA Code:
Option Explicit
Sub test()
    Dim strPath As String
    Dim wksSource As Worksheet
    Dim PT As PivotTable
    Dim pf As PivotField
    Dim pi As PivotItem
   
    Set wksSource = Worksheets("AP Pivot")
   
    Set PT = wksSource.PivotTables("PivotTable2")
   
    Set pf = PT.PivotFields("Vendor #")
   
    If pf.Orientation <> xlPageField Then
        MsgBox "There's no 'Vendor #' field in the Report Filter.  Try again!", vbExclamation
        Exit Sub
    End If
   
    strPath = "G:\"
   
    If Right(strPath, 1) <> "\" Then strPath = strPath & "\"
   
    ActiveWorkbook.ShowPivotTableFieldList = False
   
    PT.PivotCache.Refresh
   
    With pf
        .ClearAllFilters
        For Each pi In .PivotItems
            .CurrentPage = pi.Name
            wksSource.ExportAsFixedFormat Type:=xlTypePDF, Filename:=strPath & pi.Name & ".pdf"
        Next pi
        .ClearAllFilters
    End With
       End Sub
 
Last edited by a moderator:

Excel Facts

Difference between two dates
Secret function! Use =DATEDIF(A2,B2,"Y")&" years"&=DATEDIF(A2,B2,"YM")&" months"&=DATEDIF(A2,B2,"MD")&" days"
The option to save the entire workbook as opposed to the active worksheet, which is available on the Save As menu, doesn't seem to be translated in the macro I generated. You may need to copy all your pivot tables to one worksheet first, then export.
 
Upvote 0
Anyone know how I can loop through a list and change the filter based on that list and print packet to PDF?
 
Upvote 0
Hi
I am new to using VBA and I almost nothing about it. I was able to take the code in the first post and change it for my pivot table. The only bit it doesn’t like is the line
.CurrentPage = pi.Name
When I take this line out it runs but each PDF have the different vendor numbers but they all have the same data, the posit hasn’t been filtered.
Could anyone please advise why this is?
 
Upvote 0

Forum statistics

Threads
1,215,064
Messages
6,122,937
Members
449,094
Latest member
teemeren

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