Sub JointMultiFilePDF_ByAcrobat(ByVal sTargetPDF As String, ByVal arrFilePDF)
Dim oAcroApp As Object, oTargetDoc As Object, oSourceDoc As Object, oFSO As Object
Dim i As Integer, iTotalNumberOfPages_SourceToInsert As Long, iLastNumPages_Target As Long
Dim blIsOK As Boolean
Dim PDSaveFull
Set oFSO = CreateObject("Scripting.FileSystemObject")
If Not oFSO.FileExists(sTargetPDF) Then
MsgBox "File target: """ & sTargetPDF & """ is NOT available !!!", vbExclamation, "---:: NOTICE ::---"
GoTo ErrorHandle
End If
Set oAcroApp = CreateObject("Acroexch.app")
Set oTargetDoc = CreateObject("AcroExch.PDDoc")
blIsOK = oTargetDoc.Open(sTargetPDF)
If Not blIsOK Then
MsgBox "Can NOT open File target: """ & sTargetPDF & """ !!!", vbExclamation, "---:: NOTICE ::---"
GoTo ErrorHandle
End If
If IsArray(arrFilePDF) Then
For i = LBound(arrFilePDF) To UBound(arrFilePDF)
If oFSO.FileExists(arrFilePDF(i)) Then
Set oSourceDoc = CreateObject("AcroExch.PDDoc")
blIsOK = oSourceDoc.Open(arrFilePDF(i))
If blIsOK Then
iLastNumPages_Target = oTargetDoc.GetNumPages() - 1
iTotalNumberOfPages_SourceToInsert = oSourceDoc.GetNumPages
blIsOK = oTargetDoc.InsertPages(iLastNumPages_Target, oSourceDoc, 0, iTotalNumberOfPages_SourceToInsert, False)
If blIsOK Then
blIsOK = oTargetDoc.Save(PDSaveFull, sTargetPDF)
Else
MsgBox "Can NOT joint File: """ & arrFilePDF(i) & """", vbExclamation, "---:: NOTICE ::---"
End If
Else
GoTo NextFilePDF
End If
Set oSourceDoc = Nothing
End If
NextFilePDF:
Next i
End If
ErrorHandle:
Set oFSO = Nothing
Set oTargetDoc = Nothing
Set oSourceDoc = Nothing
oAcroApp.Exit
Set oAcroApp = Nothing
MsgBox "DONE", vbInformation, "---:: NOTICE ::---"
End Sub