willgarling
New Member
- Joined
- Jul 5, 2011
- Messages
- 8
- Office Version
- 365
- Platform
- Windows
I have a macro that cycles through all values in a pivot filter and saves individual PDFs for each filtered value. The problem is the macro will save the PDFs in the current excel file location. How do I adjust the macro to prompt the user for the folder location to save the PDFs? The prompt only needs to happen 1 time and then every PDF would be saved in the location selected by the user. Thanks for the help!!
Code:
Sub PrintPivotPages()
'prints a copy of pivot table for each item in page field
'assumes one page field exists
Application.ScreenUpdating = False
DirectoryLocation = ActiveWorkbook.Path
On Error Resume Next
Dim pt As PivotTable
Dim pf As PivotField
Dim pi As PivotItem
Set pt = ActiveSheet.PivotTables.Item(1)
For Each pf In pt.PageFields
For Each pi In pf.PivotItems
pt.PivotFields(pf.Name).CurrentPage = pi.Name
Name = DirectoryLocation & "\" & Range("B8").Value & ".pdf"
ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, FileName:=Name _
, Quality:=xlQualityStandard, IncludeDocProperties:=True, IgnorePrintAreas _
:=False, OpenAfterPublish:=False
Next
Next pf
Application.ScreenUpdating = True
End Sub