#1
|
|||
|
|||
Need code to combine PDF files.
Users in my organization create letters for customers inn Word. Those word documents then need to be saved as a PDF, merged with another PDF, then saved in its final form. We use Acrobat XI Pro and Word 2010. I've done a lot of customizing with the macro so far, but I just can't get this to work.
My thought is, Word has a "Create PDF and Run Action" icon, but combining files is not one of the actions it will let you choose. Also, the names of these files (documents and PDFs) will be random, depending on the user, so FilePicker will be necessary to combine the files. Each user should only need to combine 2 files, but could be more. Please help. (And I must mention that I am FAR from a professional coder. I'm self-taught, and an amateur.) |
#2
|
||||
|
||||
Google is your friend
http://lmgtfy.com/?q=vba+acrobat+combine+files+pdf Post back with the code you have so far if you still can't work it out.
__________________
Andrew Lockton Chrysalis Design, Melbourne Australia |
#3
|
|||
|
|||
I am self-taught, but I’ve done 2 week’s worth of googling to attempt to resolve this particular issue. In fact, I had visited the first 2 pages solid of those Google results. Before I post code, I will point out that it is in pieces, because I’ve been able to resolve nothing.
The first thing I wanted it to do was save my Word document as a PDF: Code:
Public Sub SavePDF() With Dialogs(wdDialogFileSaveAs) .Format = wdFormatPDF .Show End With End Sub Code:
Public Sub openDialog() Dim fd As Office.FileDialog Set fd = Application.FileDialog(msoFileDialogFilePicker) With fd AllowMultiSelect = True .Title = “Select the files to merge.” .Filters.Clear .Filters.Add “Adobe Acrobat Pro”, “*.pdf” Filters.Add “All Files”, “*.*” End With End Sub Code:
Public Sub OpenAdobe() Dim x As Variant Dim Path As String Dim File As Strikng Path = “C:\Program Files (x86)\Adobe\Acrobat 11.0\Acrobat\Acrobat.exe” Application.SendKeys (“%frm”) X = Shell(Path + “ “ + File, vbNormalFocus) End Sub |
#4
|
||||
|
||||
Try the following. It will produce a PDF in the same directory as the Word document and will prompt you to select the 'other' pdfs to include with the one from the current Word doc.
Note that you need to include a reference to Acrobat (under Tools > References) Code:
Public Sub SaveToPDF() Dim sFilePath As String ActiveDocument.Save sFilePath = ActiveDocument.FullName & ".pdf" ActiveDocument.SaveAs2 FileName:=sFilePath, FileFormat:=wdFormatPDF MergePDFs sFilePath End Sub Sub MergePDFs(sPDF As String) ' Reference required: "VBE - Tools - References - Acrobat" Dim a As Variant, i As Long, n As Long, ni As Long, p As String Dim AcroApp As New Acrobat.AcroApp Dim fd As Office.FileDialog Dim oPDF As Acrobat.CAcroPDDoc Dim oNextPDF As Acrobat.CAcroPDDoc Set oPDF = CreateObject("AcroExch.PDDoc") oPDF.Open sPDF Set oNextPDF = CreateObject("AcroExch.PDDoc") Set fd = Application.FileDialog(msoFileDialogFilePicker) With fd .AllowMultiSelect = True .Title = "Select the files to merge." .Filters.Clear .Filters.Add "Adobe Acrobat Pro", "*.pdf" If .Show = -1 Then For i = 1 To fd.SelectedItems.Count n = oPDF.GetNumPages() oNextPDF.Open .SelectedItems(i) ni = oNextPDF.GetNumPages() oPDF.InsertPages nInsertPageAfter:=n - 1, iPDDocSource:=oNextPDF, _ lStartPage:=1, lNumPages:=ni, lInsertFlags:=True oNextPDF.Close Next i End If End With oPDF.Save nType:=1, sFullPath:=sPDF oPDF.Close Set oPDF = Nothing Set oNextPDF = Nothing ' Quit Acrobat application AcroApp.Exit Set AcroApp = Nothing End Sub
__________________
Andrew Lockton Chrysalis Design, Melbourne Australia |
#5
|
|||
|
|||
YES! Thank you, brother. One last question: how would I modify it so the user could select the Save location?
Also, please email me at DCarson825@gmail.com. I'd like to find a way to thank you for your assistance with this project. Everyone's time is worth something. Thanks again. |
Tags |
acrobat, combine documents, pdf |
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
Combine multiple word files into 1 document and add section breaks | svo | Word VBA | 3 | 08-05-2015 03:05 AM |
Combine Different Word files into one file and update Table of Content | tejaspareek | Word VBA | 4 | 11-04-2014 05:50 AM |
Please help me to combine these code together | lbf200n | Word VBA | 3 | 12-09-2012 04:22 PM |
How to combine many word files in one file but to have correct pages numbers and tabl | Jamal NUMAN | Word | 6 | 04-20-2011 02:32 PM |
Combine pst files? | markg2 | Outlook | 2 | 04-26-2010 03:09 PM |