Consulting

Results 1 to 3 of 3

Thread: Export pivot table to individual PDF

  1. #1
    VBAX Newbie
    Joined
    Feb 2020
    Posts
    2
    Location

    Export pivot table to individual PDF

    Hi All,

    I need some help regarding VBA to Export pivot table to individual PDF based on each value in the filter field.
    Below is the screenshot of my pivot table:
    Capture.JPG
    I'm getting the following message when i'm running the VBA: "microsoft visual basic error 400"

    VBA CODE:

    Sub PDF_Indivudual_Summaries()
    Dim strPath As String
    Dim wksSource As Worksheet
    Dim PT As PivotTable
    Dim pf As PivotField
    Dim pi As PivotItem

    Set wksSource = Worksheets("Summary")

    Set PT = wksSource.PivotTables("PivotTable1")

    Set pf = PT.PivotFields("Department_Allocation")

    If pf.Orientation <> xlPageField Then
    MsgBox "There's no 'Department_Allocation' field in the Report Filter. Try again!", vbExclamation
    Exit Sub
    End If

    strPath = "C:\EXPORTDIRECTORY"

    If Right(strPath, 1) <> "" Then strPath = strPath & ""

    ActiveWorkbook.ShowPivotTableFieldList = False

    PT.PivotCache.MissingItemsLimit = xlMissingItemsNone
    PT.PivotCache.Refresh

    With pf
    .ClearAllFilters
    For Each pi In .PivotItems
    .CurrentPage = pi.Name
    wksSource.ExportAsFixedFormat Type:=xlTypePDF, Filename:=strPath & pi.Name & "_Code.pdf"
    Next pi
    .ClearAllFilters
    End With

    End Sub
    Attached Images Attached Images

  2. #2
    Knowledge Base Approver VBAX Wizard p45cal's Avatar
    Joined
    Oct 2005
    Location
    Surrey UK
    Posts
    5,874
    This line looks dodgy to me:
    If Right(strPath, 1) <> "" Then strPath = strPath & ""
    Try changing to:
    If Right(strPath, 1) <> "\" Then strPath = strPath & "\"
    or:
    If Right(strPath, 1) <> Application.PathSeparator Then strPath = strPath & Application.PathSeparator
    …and if you're using a Mac version, come back.
    p45cal
    Everyone: If I've helped and you can't be bothered to acknowledge it, I can't be bothered to look at further posts from you.

  3. #3
    VBAX Newbie
    Joined
    Feb 2020
    Posts
    2
    Location
    Thanks p45cal. problem solved

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •