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
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: