I am trying to use VBA to replace pages of part1.pdf with pages of part2.pdf and create mergedpdf.pdf.
I tried the following code:
What the code does right now is open doc1.pdf and save it as MergedFile.pdf. But it does not replace pages. Can anyone help me out?
I tried the following code:
VBA Code:
Sub Button1_Click()
Dim AcroApp As Acrobat.CAcroApp
Dim Part1Document As Acrobat.CAcroPDDoc
Dim Part2Document As Acrobat.CAcroPDDoc
Dim numPages As Integer
Set AcroApp = CreateObject("AcroExch.App")
Set Part1Document = CreateObject("AcroExch.PDDoc")
Set Part2Document = CreateObject("AcroExch.PDDoc")
Doc1.Open ("C:\temp\Part1.pdf")
Doc2.Open ("C:\temp\Part2.pdf")
' Insert the pages of Part2 after the end of Part1
numPages = Doc1.GetNumPages()
If Doc1.InsertPages(numPages 3, Doc2,
0, Doc2.GetNumPages(), True) = False Then
MsgBox "Cannot insert pages"
End If
If Doc1.Save(PDSaveFull, "C:\temp\MergedFile.pdf") = False Then
MsgBox "Cannot save the modified document"
End If
Doc1.Close
Doc2.Close
AcroApp.Exit
Set AcroApp = Nothing
Set Part1Document = Nothing
Set Part2Document = Nothing
MsgBox "Done"
End Sub
What the code does right now is open doc1.pdf and save it as MergedFile.pdf. But it does not replace pages. Can anyone help me out?