Append to PDF with Macro

  • Hi,


    I'm trying to export pdf files from from excel. This is in relation to data for various owners of business. The pdf file is current exported with the business name (Filename:=ActiveWorkbook.Path & "\" & ActiveSheet.Range("O7").Value) . Typically each business owner has one location, where the macro works well. However if the business owner has more than location rather than appending to the existing pdf file, the file is overwritten. How would you edit the code to append to a pdf where one currently exists?


    As an alternative - I do have an actual printer setup which will print to pdf and a pop up box shows asking for a file name to be given, it also allows for the option to append to pdf. Not sure if this could be used instead of the excel feature to export to pdf instead.


    Many Thanks,


  • Perhaps you could just create multiple pdf's for each Business. First checking if a file already exists in the save location and if it does save a temporary pdf.

    Then you could install an command line tool such as pdftk (https://www.pdflabs.com/tools/pdftk-server/) and then you a shell script to combine the two files. then delete the temporary file. eg:


    Code
    1. Dim command As String
    2. command = "pdftk ""Business Name.pdf"" tmp.pdf cat output cat.pdf && move /Y cat.pdf ""Business Name.pdf"" && del tmp.pdf /F"
    3. CreateObject("WScript.Shell").Run command, vbHide, True