Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 08-13-2015, 03:59 PM
D1TrueGod D1TrueGod is offline Need code to combine PDF files. Windows 8 Need code to combine PDF files. Office 2010 32bit
Novice
Need code to combine PDF files.
 
Join Date: Aug 2015
Posts: 3
D1TrueGod is on a distinguished road
Question 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.)
Reply With Quote
  #2  
Old 08-13-2015, 07:17 PM
Guessed's Avatar
Guessed Guessed is offline Need code to combine PDF files. Windows 7 32bit Need code to combine PDF files. Office 2010 32bit
Expert
 
Join Date: Mar 2010
Location: Canberra/Melbourne Australia
Posts: 3,932
Guessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant future
Default

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
Reply With Quote
  #3  
Old 08-14-2015, 05:35 AM
D1TrueGod D1TrueGod is offline Need code to combine PDF files. Windows 8 Need code to combine PDF files. Office 2010 32bit
Novice
Need code to combine PDF files.
 
Join Date: Aug 2015
Posts: 3
D1TrueGod is on a distinguished road
Default

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
And, since the documents needing combined will always have different names, I need the user to be able to choose the documents:

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
In frustration, I also considered opening Acrobat and sending commands:

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
I’m sure it’s obvious I don’t do this for a living, but I learn quickly, and have some grasp of how computer programming works; thus, I’ve been chosen to attempt to write this. I would greatly appreciate any assistance, and would be willing to speak with someone via phone if you think that would make the process easier. Thank you in advance.
Reply With Quote
  #4  
Old 08-14-2015, 05:09 PM
Guessed's Avatar
Guessed Guessed is offline Need code to combine PDF files. Windows 7 32bit Need code to combine PDF files. Office 2010 32bit
Expert
 
Join Date: Mar 2010
Location: Canberra/Melbourne Australia
Posts: 3,932
Guessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant future
Default

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
Reply With Quote
  #5  
Old 08-15-2015, 06:15 AM
D1TrueGod D1TrueGod is offline Need code to combine PDF files. Windows 8 Need code to combine PDF files. Office 2010 32bit
Novice
Need code to combine PDF files.
 
Join Date: Aug 2015
Posts: 3
D1TrueGod is on a distinguished road
Default

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.
Reply With Quote
Reply

Tags
acrobat, combine documents, pdf

Thread Tools
Display Modes


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
Need code to combine PDF files. Combine Different Word files into one file and update Table of Content tejaspareek Word VBA 4 11-04-2014 05:50 AM
Need code to combine PDF files. Please help me to combine these code together lbf200n Word VBA 3 12-09-2012 04:22 PM
Need code to combine PDF files. 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
Need code to combine PDF files. Combine pst files? markg2 Outlook 2 04-26-2010 03:09 PM

Other Forums: Access Forums

All times are GMT -7. The time now is 12:46 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2024 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft