Is there any efficient way to insert a page in pdf via VBA?
Hi there,
I am using PDDoc.InsertPages to insert 01 pdf page to another 400 page pdf and it takes about 5 minutes. Is there any other way to do it more efficiently? After all, it's only 01 page insert.
My environment is excel 2010 and Acrobat X Pro.
Here is my code and it works well except too slow!!!
Public Function MergePDF(SourceFile, TargetFile, MergedFile)
On Error GoTo Error
Dim AcroApp As Acrobat.AcroApp
Dim Part1Document As Acrobat.AcroPDDoc
Dim Part2Document As Acrobat.AcroPDDoc
Dim numPages As Integer
Set AcroApp = CreateObject("AcroExch.App")
Set Part1Document = CreateObject("AcroExch.PDDoc")
Set Part2Document = CreateObject("AcroExch.PDDoc")
Part1Document.Open (SourceFile)
Part2Document.Open (TargetFile)
' Insert the pages of Part2 after the end of Part1
numPages = Part1Document.GetNumPages()
If Part1Document.InsertPages(numPages - 1, Part2Document, 0, Part2Document.GetNumPages(), True) = True Then
Call Part1Document.Save(PDSaveFull, MergedFile)
End If
Part1Document.Close
Part2Document.Close
AcroApp.Exit
Set AcroApp = Nothing
Set Part1Document = Nothing
Set Part2Document = Nothing
Exit Function
Error:
End Function
