+ Reply to Thread
Results 1 to 8 of 8

VBA export sheets as PDFs, merge with existing PDFs

  1. #1
    Registered User
    Join Date
    07-20-2015
    Location
    New York, US
    MS-Off Ver
    2013
    Posts
    43

    VBA export sheets as PDFs, merge with existing PDFs

    Hi gurus,

    I am currently using the below code to export sheets in a workbook as PDFs. Each PDF's Filename is the name of the exported sheet. The FolderPath is C:\PDFs\Bi-Weekly Syndication Reports.

    Please Login or Register  to view this content.
    This code results in an error if the FolderPath already exists so I have to delete it each time before running the macro (annoying). This is what I am trying to achieve:
    • If the FolderPath does NOT exist, create the FolderPath.
    • If the FolderPath does exist, follow the FolderPath.
    • If a PDF is exported with a Filename that does NOT exist in the folder, create the file.
    • If a PDF is exported with a Filename that does exist in the folder, merge the new PDF with the existing PDF.

    Any help would be MUCH appreciated! Thanks in advance to anyone who answers!

  2. #2
    Forum Expert Kenneth Hobson's Avatar
    Join Date
    02-05-2007
    Location
    Tecumseh, OK
    MS-Off Ver
    Office 365, Win10Home
    Posts
    2,573

    Re: VBA export sheets as PDFs, merge with existing PDFs

    Excel does not have a method to merge existing PDF files. We can utilize 3rd party software in VBA to do it. The best one is of course Adobe Acrobat, not Adobe Reader. If you don't have that, PDFCreator, earlier version, is decent. Otherwise, shelling to something like PDFSam and passing input parameter values will suffice. I discussed those at: http://www.mrexcel.com/forum/excel-q...lications.html

    For making a folder, one of these two methods will suffice.
    Please Login or Register  to view this content.
    Last edited by Kenneth Hobson; 08-20-2015 at 05:10 PM.

  3. #3
    Registered User
    Join Date
    07-20-2015
    Location
    New York, US
    MS-Off Ver
    2013
    Posts
    43

    Re: VBA export sheets as PDFs, merge with existing PDFs

    Thanks for the prompt response Kenneth. I just downloaded and installed PDFCreator. Unfortunately I don't know what to do with your above code.

    Could you please elaborate on how to integrate it with my existing code? Appreciate it!

  4. #4
    Forum Expert Kenneth Hobson's Avatar
    Join Date
    02-05-2007
    Location
    Tecumseh, OK
    MS-Off Ver
    Office 365, Win10Home
    Posts
    2,573

    Re: VBA export sheets as PDFs, merge with existing PDFs

    I showed 2 ways to use PDFCreator in the referenced thread. Which version did you download and install? The newer version is slow.

  5. #5
    Registered User
    Join Date
    07-20-2015
    Location
    New York, US
    MS-Off Ver
    2013
    Posts
    43

    Re: VBA export sheets as PDFs, merge with existing PDFs

    Just checked and I actually got the 2.1.2 version. Sorry I'm new to using vba while utilizing 3rd party software so I don't understand your code or how to integrate it with my current stuff :/

  6. #6
    Forum Expert Kenneth Hobson's Avatar
    Join Date
    02-05-2007
    Location
    Tecumseh, OK
    MS-Off Ver
    Office 365, Win10Home
    Posts
    2,573

    Re: VBA export sheets as PDFs, merge with existing PDFs

    To use my routine, you need to build the string array with your file names and pass the name of the merged pdf that you want to create. Before I show you the exact method, why not try a test to merge two of your files? Simply replaced the values in the test routine. Be sure to set the reference to PDFCreator as I explained.

    After you try this, I will show you how to build the string array if needed. Keep in mind that Adobe Reader will open for each pdf file. Either close each or take a coffee break and it will close them for you. As I said, it is not perfect but does work, eventually. Be sure that you can live with it before I show you more.


    Please Login or Register  to view this content.

  7. #7
    Registered User
    Join Date
    07-20-2015
    Location
    New York, US
    MS-Off Ver
    2013
    Posts
    43

    Re: VBA export sheets as PDFs, merge with existing PDFs

    I've been trying for a few days now to get your code to work for me. All that happens is a black box appears for a second then disappears.

    For me to get this going I think you'd have to dumb the process down a lot for me.

    I understand if you don't have the time to do this. Thanks a lot for your help so far regardless.

  8. #8
    Forum Expert Kenneth Hobson's Avatar
    Join Date
    02-05-2007
    Location
    Tecumseh, OK
    MS-Off Ver
    Office 365, Win10Home
    Posts
    2,573

    Re: VBA export sheets as PDFs, merge with existing PDFs

    Adding the reference and the two existing file names and paths and the name and filepath to merge the two files to seems about as simple as one can get.

    As I said, it is not the fasted way to go but does work. IF you can't get the simple example, the more complete solution won't work either.

    Feel free to attach a simple file with the code that you tried and I will check it out with my file paths.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Replies: 0
    Last Post: 06-24-2015, 02:34 AM
  2. how to close pdfs?
    By daveyc18 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 05-28-2015, 08:43 AM
  3. Printing PDFs file with Excel Sheets With Page Numbers
    By reachharry in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 08-24-2014, 10:59 AM
  4. Saving Multiple Sheets as Separate PDFs
    By csun in forum Excel General
    Replies: 1
    Last Post: 01-09-2014, 09:54 PM
  5. Need help Merge PDFs using VBA
    By JieJenn in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 12-03-2012, 01:13 PM
  6. Saving Worksheet as different pdfs
    By manny_cb in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 08-17-2009, 03:49 AM

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1