title: Create PDF for each pivot filter
body: <p>I currently have a pivot table which created a statement of outstanding invoices, which is filtered by account name. I would like to create a macro where excel makes a PDF statement for each account.</p>
  
  <p>I have no knowledge of VBA so I got the code below by searching google and edited it for my pivot table. </p>
  
  <p>However when I try to run it excel does not like this line “.CurrentPage = pi.Name”. When I take this out it does run and created several PDFs with the correct account name, but all the statements are the same just. </p>
  
  <p>Is anyone able to help?</p>
  
  <pre><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("PivotTable1")
  
  Set pf = PT.PivotFields("ACCOUNT")
  
  If pf.Orientation &lt;&gt; xlPageField Then
  MsgBox "There's no 'ACCOUNT' field in the Report Filter. Try again!", vbExclamation
  Exit Sub
  End If
  
  strPath = "T:\"
  
  If Right(strPath, 1) &lt;&gt; "\" Then strPath = strPath &amp; "\"
  
  ActiveWorkbook.ShowPivotTableFieldList = False
  
  PT.PivotCache.Refresh
  
  With pf
  .ClearAllFilters
  For Each pi In .PivotItems
  .CurrentPage = pi.Name
  wksSource.ExportAsFixedFormat Type:=xlTypePDF, Filename:=strPath &amp; pi.Name &amp; ".pdf"
  Next pi
  .ClearAllFilters
  End With
  End Sub
  </code></pre>