Sub MergePDFs(nDocs As Integer, BaseFileName As String)
Dim AcroApp As Acrobat.CAcroApp
Dim iDoc As Integer
Dim BaseDocument As Acrobat.CAcroPDDoc
Dim PartDocument As Acrobat.CAcroPDDoc
Dim numPages As Integer
Set AcroApp = CreateObject("AcroExch.App")
Set BaseDocument = CreateObject("AcroExch.PDDoc")
Set PartDocument = CreateObject("AcroExch.PDDoc")
BaseDocument.Open (ActiveWorkbook.Path & "\" & BaseFileName & "_" & 1 & ".pdf")
For iDoc = 2 To nDocs
PartDocument.Open (ActiveWorkbook.Path & "\" & BaseFileName & "_" & iDoc & ".pdf")
numPages = BaseDocument.GetNumPages()
' Insert the pages of Part after the end of Base
If BaseDocument.InsertPages(numPages - 1, PartDocument, 0, PartDocument.GetNumPages(), True) = False Then
MsgBox "Cannot insert pages"
End If
PartDocument.Close
Next iDoc
If BaseDocument.Save(PDSaveFull, ActiveWorkbook.Path & "\" & BaseFileName & ".pdf") = False Then
MsgBox "Cannot save the modified document"
Else
' Remove intermediate documents
For iDoc = 1 To nDocs
Kill ActiveWorkbook.Path & "\" & BaseFileName & "_" & iDoc & ".pdf"
Next iDoc
End If
BaseDocument.Close
AcroApp.Exit
Set AcroApp = Nothing
Set BaseDocument = Nothing
Set PartDocument = Nothing
End Sub