Consulting

Results 1 to 5 of 5

Thread: Able to set the Order of PDF Merging Using Adobe Acrobat?

  1. #1

    Able to set the Order of PDF Merging Using Adobe Acrobat?

    Dear all,

    I would like to expand from this PDF Merging thread [47310-Need-code-to-merge-PDF-files-in-a-folder-using-adobe-acrobat-X] from before (which is now Closed). I am using the Code found in Reply #4 by ZVI which works great for me. My version specifies the folder path and it converts all Word files into PDF then merge it alphabetically.

    However there is one specific file in my folder that must appear first, then the rest can follow. This file doesn't always sit at the top alphabetically. Is there a way to specify the order?
    Thanks in advance for your kind assistance

  2. #2
    VBAX Mentor
    Joined
    Aug 2012
    Posts
    367
    Location
    can you use word, and 'print to pdf'?

    you can use vba to open and print files in any order you specify, and it 'should' be a simple step to open and join pdf's in word
    Remember: it is the second mouse that gets the cheese.....

  3. #3
    Quote Originally Posted by werafa View Post
    can you use word, and 'print to pdf'?

    you can use vba to open and print files in any order you specify, and it 'should' be a simple step to open and join pdf's in word
    I do have another function that saves all the Word files as PDF, before running the command to combine all PDFs.
    I was able to solve this problem though, with some crafty combination of PDF-timing and changes in names. Thank you!

  4. #4
    Moderator VBAX Sage SamT's Avatar
    Joined
    Oct 2006
    Location
    Near Columbia
    Posts
    7,814
    Location
    Merge Specialdoc
    
    for each otherdocs
       If not SpecialDoc then
         Merge Doc
       End if
    Next
    I expect the student to do their homework and find all the errrors I leeve in.


    Please take the time to read the Forum FAQ

  5. #5
    Have a very urgent error... I would really appreciate any help you can provide me!

    Users are reporting that they are getting the following error - Run-Time Error 429: ActiveX Component Can't Create Object. This is very curious as my settings are the same as theirs, and I do not experience this error.
    It debugs to:
    Set PartDocs(i) = CreateObject("AcroExch.PDDoc")
    I tried changing it to below, which still generated the Error 429:
    Set PartDocs(i) = New Acrobat.AcroPDDoc
    And yes, these users have Adobe Acrobat XI Pro and the file being tested does have 'Adobe Acrobat 10.0 Type Library' checked.
    I do not have a reference called simply 'Acrobat'.

    Sub MergePDFs()
    ' Reference required: "VBE - Tools - References - Acrobat"
     
      ' --> Settings, change to suit
      Const MyPath = "C:\Temp"            ' Path where PDF files are stored
       Const MyFiles = "1.pdf,2.pdf,3.pdf"  ' List of PDFs to ne merged
      Const DestFile = "MergedFile.pdf"   ' The name of the merged file
      ' <-- End of settings
     
      Dim a As Variant, i As Long, n As Long, ni As Long, p As String
      Dim AcroApp As New Acrobat.AcroApp, PartDocs() As Acrobat.CAcroPDDoc
     
      If Strings.Right(MyPath, 1) = "\" Then p = MyPath Else p = MyPath & "\"
      a = Split(MyFiles, ",")
      ReDim PartDocs(0 To UBound(a))
     
      On Error GoTo exit_
      If Len(Dir(p & DestFile)) Then Kill p & DestFile
      For i = 0 To UBound(a)
        ' Check PDF file presence
        If Dir(p & Trim(a(i))) = "" Then
          MsgBox "File not found" & vbLf & p & a(i), vbExclamation, "Canceled"
          Exit For
        End If
    
        ' Open PDF document
        'Set PartDocs(i) = CreateObject("AcroExch.PDDoc")
        Set PartDocs(i) = New Acrobat.AcroPDDoc
        PartDocs(i).Open p & Strings.Trim(a(i))
     
       If i Then
          ' Merge PDF to PartDocs(0) document
          ni = PartDocs(i).GetNumPages()
          If Not PartDocs(0).InsertPages(n - 1, PartDocs(i), 0, ni, True) Then
            MsgBox "Cannot insert pages of" & vbLf & p & a(i), vbExclamation, "Canceled"
          End If
          ' Calc the number of pages in the merged document
          n = n + ni
          ' Release the memory
          PartDocs(i).Close
          Set PartDocs(i) = Nothing
        Else
          ' Calc the number of pages in PartDocs(0) document
          n = PartDocs(0).GetNumPages()
        End If
      Next
     
      If i > UBound(a) Then
        ' Save the merged document to DestFile
        If Not PartDocs(0).Save(PDSaveFull, p & DestFile) Then
          MsgBox "Cannot save the resulting document" & vbLf & p & DestFile, vbExclamation, "Canceled"
        End If
      End If
     
    exit_:
     
      ' Inform about error/success
      If Err Then
        MsgBox Err.Description, vbCritical, "Error #" & Err.Number
      ElseIf i > UBound(a) Then
        MsgBox "The resulting file is created:" & vbLf & p & DestFile, vbInformation, "Done"
      End If
     
      ' Release the memory
      If Not PartDocs(0) Is Nothing Then PartDocs(0).Close
      Set PartDocs(0) = Nothing
     
      ' Quit Acrobat application
      AcroApp.Exit
      Set AcroApp = Nothing
     
    End Sub

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •