Microsoft Office Forums

Go Back   Microsoft Office Forums > >

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
  #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: 4,184
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
 

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
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 03:46 AM.


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