Skip to main content
Known Participant
August 17, 2017
Question

Can I run a JavaScript in Acrobat through Excel VBA?

  • August 17, 2017
  • 2 replies
  • 5704 views

Here's the quick version of my question. I have an excel spreadsheet that writes a JavaScript script in column A of my spreadsheet based on user inputs. I want to be able to run a vba macro in excel that opens acrobat and runs that javascript. I've already figured out how to open Acrobat using VBA in excel, but have not figured out how to open the JS debugger, paste my code in, and run it.

In summary: How can I open the acrobat debugger and run my code using an excel VBA macro?

Any help would be much appreciated.

Thanks

This topic has been closed for replies.

2 replies

Thom Parker
Community Expert
Community Expert
August 17, 2017

Here's a link to the reference you need. It's an old doc, but nothing has changed.

http://www.adobe.com/content/dam/Adobe/en/devnet/acrobat/pdfs/VBJavaScript.pdf

Thom Parker - Software Developer at PDFScriptingUse the Acrobat JavaScript Reference early and often
Known Participant
August 17, 2017

For some reason in this line below that I got from that link it won't let me use a string variable as the file path.

If gPDDoc.Open("c:\adobe.pdf") Then

I want to use a variable instead of typing out the file path. However, when I use a variable declared as String it doesn't work. Example  below:

Dim OpenDoc As String

OpenDoc = "c:\adobe.pdf"

If gPDDoc.Open(OpenDoc) Then

The entire code works if I type out the file path, but does not work if I use the string variable to replace my file path.

What's the difference between "If gPDDoc.Open(OpenDoc) Then" and "If gPDDoc.Open("c:\adobe.pdf") Then"      ?

Also, what's the command to execute the console once all of my script is in there?

try67
Community Expert
Community Expert
August 17, 2017

I don't think you can use the JS Object in VBA to execute commands via the Console. You need to execute them directly.

Bernd Alheit
Community Expert
Community Expert
August 17, 2017

In the Acrobat SDK documentation look for the VB JavaScript bridge.