Need help in merging PDF files through VBA

SHIRDESH

New member
Joined
Oct 4, 2016
Messages
1
Reaction score
0
Points
0
Hello I am new to this group and was wondering if anyone could help me with how to merge multiple pdf files in single file using VBA macro.
I have to create a final Pdf file that has all the different reports in it and i get individual reports in pdf format from different teams. I am using pdf creator version 2.3.2. I found the code online but it throws an error
when the code reaches .MergeAllJobs it throws an error saying Run time error and " The queue must not be empty". the test file i am testing does exists in those location that i mentioned in the code. below s the code for your reference.

appreciate all the help guys.

Code:
Sub Test_PDFCreatorCombine()
  Dim fn(0 To 1) As String, s As String
  fn(0) = "C:\Users\SVellore\Documents\VBA\Report Tool\_Projects\_02-Templates\NA\temp1.pdf"
  fn(1) = "C:\Users\SVellore\Documents\VBA\Report Tool\_Projects\_02-Templates\NA\temp2.pdf"
  s = "C:\Users\SVellore\Documents\VBA\Report Tool\_Projects\_02-Templates\NA\PDFCreatorCombined.pdf"


  PDFCreatorCombine fn(), s


  If vbYes = MsgBox(s, vbYesNo + vbQuestion, "Open?") Then Shell ("cmd /c " & """" & s & """")
End Sub


'Macro Purpose: Print to PDF file using PDFCreator
' Designed for early bind, set reference to: PDFCreator - Your OpenSource PDF Solution

Sub PDFCreatorCombine(sPDFName() As String, sMergedPDFname As String)
  Dim oPDF As PDFCreator.PdfCreatorObj, q As PDFCreator.Queue
  Dim pj As PrintJob
  Dim v As Variant, i As Integer
  Dim fso As Object


  Set fso = CreateObject("Scripting.FileSystemObject")


  Set q = New PDFCreator.Queue
  With q
  'On Error Resume Next


    .Initialize
    If LBound(sPDFName) = 0 Then
      .WaitForJobs UBound(sPDFName) + 1, 1
      Else
      .WaitForJobs UBound(sPDFName), 1
    End If




    Set oPDF = New PDFCreator.PdfCreatorObj  'PDFCreator.clsPDFCreator


    i = 0
    For Each v In sPDFName()
      If fso.FileExists(v) Then oPDF.PrintFile v
      i = i + 1
    Next v
    
    On Error GoTo EndNow
    .MergeAllJobs


    Set pj = q.NextJob
    With pj
      .SetProfileByGuid "DefaultGuid"
      .SetProfileSetting "Printing.PrinterName", "PDFCreator"
      .SetProfileSetting "Printing.SelectPrinter", "SelectedPrinter"
      .SetProfileSetting "OpenViewer", "false"
      .SetProfileSetting "OpenWithPdfArchitect", "false"
      .SetProfileSetting "ShowProgress", "false"
      .ConvertTo sMergedPDFname
    End With
EndNow:
    .ReleaseCom
  End With
End Sub


Thanks,
shirdesh
 
Top