Results 1 to 4 of 4

Thread: Append to pdf VBA
Thanks Thanks: 0 Likes Likes: 0

  1. #1
    Board Regular diddi's Avatar
    Join Date
    May 2004
    Location
    Shepparton, Australia
    Posts
    2,552
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default Append to pdf VBA

    Morning all.
    I am hoping to find advice for a Shell( ) or other method to add sheets to a pdf file.
    I have tried several pdf generators / merging programs that support command line, but cannot get any of them to work.

    I have a standard sheet which is filled by VBA and saved to PDF then repopulated and appended to the same PDF. There may be 30 or more pages to add.

    I would prefer to use a free PDF program.
    TIA
    The more you learn, the more you realise how little you know. Excel 2003 and 2010 / Win7
    Code:
    Sub HintForGoodResults( )
        If yourcode Is indented Then
            "it is easier to for everyone to understand" AND "others are more likely to give assistance"
        Else
            "errors are much harder to find" OR "others dont bother"
        End If
    End Sub

  2. #2
    Board Regular Kenneth Hobson's Avatar
    Join Date
    Feb 2007
    Location
    Tecumseh, OK
    Posts
    3,051
    Post Thanks / Like
    Mentioned
    7 Post(s)
    Tagged
    0 Thread(s)

    Default Re: Append to pdf VBA

    The string to pass to Shell() depends on the 3rd party application's command line options. In this thread, we discussed PDFsam and PDFtk. I also gave VBA code for PDFcreator and Acrobat.
    https://www.mrexcel.com/forum/excel-...using-vba.html

    If you get stuck or need help with another application, post back.

  3. #3
    Board Regular diddi's Avatar
    Join Date
    May 2004
    Location
    Shepparton, Australia
    Posts
    2,552
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default Re: Append to pdf VBA

    thx for that. i did try PDFsam but could not get the shell script to work, so hopefully i can use your link but better success.
    The more you learn, the more you realise how little you know. Excel 2003 and 2010 / Win7
    Code:
    Sub HintForGoodResults( )
        If yourcode Is indented Then
            "it is easier to for everyone to understand" AND "others are more likely to give assistance"
        Else
            "errors are much harder to find" OR "others dont bother"
        End If
    End Sub

  4. #4
    Board Regular lrobbo314's Avatar
    Join Date
    Jul 2008
    Location
    California
    Posts
    2,403
    Post Thanks / Like
    Mentioned
    4 Post(s)
    Tagged
    1 Thread(s)

    Default Re: Append to pdf VBA

    I did something something similar to this using Python with a library called PyPDF2.

    You could run VBA that would save each sheet in your workbook to a certain folder, then call open the Python script. The script opens a prompt which asks you to enter the folder where your PDFs are. Then it combines all of the PDFs into 1 file called Result.pdf.

    Here's the Python Script.

    Code:
    from PyPDF2 import PdfFileMerger
    import os
    pdfs = []
    
    
    path = input('Enter path of directory with PDFs to merge>>>')
    
    
    for file in os.listdir(path + "\\"):
        if file.endswith('.pdf'):
            pdfs.append(path + "\\" + file)
    
    
    merger = PdfFileMerger()
    
    
    for pdf in pdfs:
        merger.append(pdf)
    
    
    merger.write(path + "\" + 'Result.pdf')
    Last edited by lrobbo314; Aug 18th, 2019 at 11:32 PM.
    To add code to a workbook. Hit Alt+F11. Hit Alt+I+M to insert new module. Then paste code.
    Array formulas must be entered by hitting Ctrl+Shift+Enter.

    We can't solve problems by using the same kind of thinking we used when we created them.

    Imagination is more important than knowledge.

Some videos you may like

User Tag List

Tags for this Thread

Like this thread? Share it with others

Like this thread? Share it with others

Posting Permissions

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