Skip to main content
New Participant
October 25, 2022
Question

VBA ReplacePages Method Fails after new Acrobat Pro Install

  • October 25, 2022
  • 2 replies
  • 1049 views

I have a macro that opens 2 pdf's and replaces pages from one with the pages from the other. It was working before I moved to a new computer. Both computers are running Acrobat Pro -- but the older one was using 2017 version, and the new one is using the newest Acrobat pro subscription license.

 

Is there something that's changed that would make this method now fail?

 

        If Doc1.ReplacePages(Doc1.GetNumPages - 7, Doc2, 0, Doc2.GetNumPages, 1) = False  Then
            MsgBox "Cannot replace pages"
            Exit Sub
        End If

 

My code executes fine - but now returns "FALSE" but previously was working fine.

 

Thanks!

This topic has been closed for replies.

2 replies

New Participant
August 28, 2023

Hi, @Steven267925802wen 

I am also encountering the same error. After installing the new Acrobat, the ReplacePages method started returning False.

Have there been any developments since then? If there have been any updates, I would greatly appreciate it if you could share the information.

Thank you in advance.

Thom Parker
Community Expert
Community Expert
August 28, 2023

I would strongly suggest that you put all of your JavaScript code into an Acrobat folder level function. Test it from the Acrobat Console window to make sure it is all working, then call the folder level function from your VBA.

 

The conversion from the VBA context into the JavaScript context is not clean one. This is especially true for non-generic objects such as the Doc object. In fact, the first code posted by steven is problematic for this reason. He does not show the code used to acquire the Doc objects. So we don't know if they are actually JS docs. But even if they are, it is better to call the document functions directly from the JSO.  It may the use of the doc object that was the problem in the first place. But regardless. You are protected from these types of issues by using a folder level function to perform all of the Acrobat JavaScript functionality. 

   

Thom Parker - Software Developer at PDFScriptingUse the Acrobat JavaScript Reference early and often
New Participant
August 29, 2023

Thank you for the advice you provided.

I would like to try using the replacePages method with JavaScript from VBA, but I can't find any samples.

Do you know of any samples for calling the method?

Legend
October 26, 2022

Are you able to do the insertion manually on those exact files (using Organise pages or drag and drop of thumbnails). The first thing is to verify that it isn't a problem with the files.

New Participant
October 26, 2022

Hi, thanks for responding. Yes, I am able to manually do that.

 

Also FYI - I checked the reference libraries in VBA that are enabled & have Adobe 10.0 Type Library enabled, and also added Acrobat Access 3.0 Type Library for good measure. No luck.