2

I have an Acrobat .pdf document which includes a Javascript global variable. I am trying to get code in VBA that will reference the value of this global from Acrobat, but I can't quite figure out the necessary syntax to do so. I assume that this is a trivially simple question, but nonetheless it has me stumped.

Basically, in my Acrobat/.pdf document, I have some very simple Javascript that defines:

global.ReturnString = "Arbitrary String";

and then I have another very simple button that displays that return string as an app alert:

app.alert(global.ReturnString);

All I want to do is to be able to reproduce this extremely simple functionality via an Excel message box. In other words I just want to write some working VBA code that will successfully execute this in Excel:

MsgBox (SomeSortOfPointerToAcrobat.Global.ReturnString)

So far I haven't been able to get this to work. I've tried using GetJSObject as the construct to pass info between Acrobat and Excel (VBA code below). I am currently opening the .pdf file in an Excel userform at the time that I am trying to reference the JavaScript global variable in Excel VBA:

Dim gAPP As Acrobat.CAcroApp
Dim gPDDOC As Acrobat.CAcroPDDoc
Dim jso As Object


Set gAPP = CreateObject("AcroExch.App")
Set gPDDOC = CreateObject("AcroExch.PDDoc")

If gPDDOC.Open("C:\path\testdoc.pdf") Then
    Set jso= gPDDOC.GetJSObject
    MsgBox (jso.Global.ReturnString)
End If

But this always leads to run-time error '438': Object doesn't support this property or method.

I have the Adobe Acrobat 10.0 Type Library added to my VBA project.

Any suggestions?

Again, I apologize for what I assume is a very trivial question. I'm happy to clarify as needed for any needed details that I've left out of this description of the question.

Ben Rhys-Lewis
  • 3,118
  • 8
  • 34
  • 45
John Q. Noob
  • 181
  • 1
  • 2
  • 18
  • 2
    I hate adobe. I think your code is accurate but may want to double check [here](http://help.adobe.com/livedocs/acrobat_sdk/9/Acrobat9_HTMLHelp/wwhelp/wwhimpl/js/html/wwhelp.htm?href=IAC_DevApp_OLE_Support.100.13.html&accessible=true). – findwindow Mar 01 '16 at 18:13
  • @findwindow You were correct, thank you! After much searching, I realized that in this case, the JSO portion of the code actually is fine as is. My actual issue is related to the location of the code that defines the global variable. It works with no problems in Acrobat, but when I try to do the same things through VBA, that code is not being called (so the global isnt actually being defined), and THAT is the cause of my particular issue, not the getJSObject syntax as I initially believed. – John Q. Noob Mar 02 '16 at 18:19

1 Answers1

0

(Marking as answered so that this no longer shows as an open question)

ANSWER: Code was, in fact, correct as-is in the original question.

John Q. Noob
  • 181
  • 1
  • 2
  • 18