Question
Function InsertPages() [from "AcroExch.PDDoc"] does not insert pages in VBA.
Hello guys,
I am new here. I wrote a simple code which needs to merge 2 PDF files.
Problem:
- The fucntion InsertPages() does not want to insert pages from another PDF file.
- I am not getting any errors.
- I am always getting FALSE returned from InserPages().
Question:
- Does anybody have an idea?
As you can see, the code is super simple.
Sub mergePDFfiles()
Dim Aapp As Acrobat.AcroApp
Dim Doc01 As Acrobat.AcroPDDoc
Dim Doc02 As Acrobat.AcroPDDoc
Dim Doc03 As Acrobat.AcroPDDoc
Set Aapp = CreateObject("AcroExch.App")
Set Doc01 = CreateObject("AcroExch.PDDoc")
Set Doc02 = CreateObject("AcroExch.PDDoc")
Set Doc03 = CreateObject("AcroExch.PDDoc")
Aapp.Show
'------------------------
Dim sName00, sName01, sName02, sName03 As String
Dim sPfad00, sPfad01, sPfad02, sPfad03 As String
Dim vAnzahl01, vAnzahl02, vAnzahl03 As Long
sPfad00 = ThisWorkbook.Path + "\DocTOTAL.pdf"
sPfad01 = ThisWorkbook.Path + "\Doc_01.pdf"
sPfad02 = ThisWorkbook.Path + "\Doc_02.pdf"
sPfad03 = ThisWorkbook.Path + "\Doc_03.pdf"
If Doc01.Open(sPfad01) Then
sName01 = Doc01.GetFileName()
vAnzahl01 = Doc01.GetNumPages()
MsgBox sName01 + " has " + CStr(vAnzahl01) + " pages and is open."
End If
If Doc02.Open(sPfad02) Then
sName02 = Doc02.GetFileName()
vAnzahl02 = Doc02.GetNumPages()
MsgBox sName02 + " has " + CStr(vAnzahl02) + " pages and is open."
End If
If Doc03.Open(sPfad03) Then
sName03 = Doc03.GetFileName()
vAnzahl03 = Doc03.GetNumPages()
MsgBox sName03 + " has " + CStr(vAnzahl03) + " pages and is open."
End If
If Doc01.InsertPages(vAnzahl01, Doc02, 0, vAnzahl02, 0) = False Then
MsgBox "Document not inserted"
Else
MsgBox "Document inserted"
End If
If Doc01.Save(PDSaveFull, sPfad00) = False Then
MsgBox "Document not saved"
Else
MsgBox "Document saved under " + sPfad00
End If
'------------------------
Doc01.Close
Doc02.Close
Doc03.Close
Aapp.Exit
Set Aapp = Nothing
Set Doc03 = Nothing
Set Doc02 = Nothing
Set Doc01 = Nothing
End Sub