Question
Replacing pdf pages using VBA
Hello guys,
I've been tryin to use the code of Karl Heinz to replace pages between two PDFs using excel. Unfortunately, it doesn't work. All it does on my system is save the first pdf under a different name without having exchanges any pages.
Here is the 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
