Replacing pdf pages using VBA

New Here ,
Jun 08, 2020

Copy link to clipboard

Copied

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

 

TOPICS
Acrobat SDK and JavaScript

Views

219

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more

Replacing pdf pages using VBA

New Here ,
Jun 08, 2020

Copy link to clipboard

Copied

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

 

TOPICS
Acrobat SDK and JavaScript

Views

220

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Jun 08, 2020 0
Adobe Community Professional ,
Jun 08, 2020

Copy link to clipboard

Copied

Have you done any debug? 

Are any messages displayed? 

Where are Doc1 and Doc2 defined and created?

 

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Jun 08, 2020 0
Adobe Community Professional ,
Jun 08, 2020

Copy link to clipboard

Copied

Why does you use numPages 3 at InsertPages?

 

 

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Jun 08, 2020 0