View Single Post
 
Old 08-14-2015, 05:09 PM
Guessed's Avatar
Guessed Guessed is online now Windows 7 32bit Office 2010 32bit
Expert
 
Join Date: Mar 2010
Location: Canberra/Melbourne Australia
Posts: 3,978
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