troubleshooting Question

VBA ScriptControl to run Java Script Function

Avatar of kriskyk
kriskyk asked on
Microsoft OfficeMicrosoft ExcelMicrosoft Word
16 Comments1 Solution10858 ViewsLast Modified:
I am tryng to insert the following java script function in word doc project to obtain a value from a cookie.

function getCookie(name) {
        var cookieArray = document.cookie.split(";");
        for (index in cookieArray)
            var keyValuePair = cookieArray[index].split("=");
            var key = keyValuePair[0];
            key  = key.replace(/^\s+|\s+$/g, "");
            if (key == name)
                var value = keyValuePair[1];
                return value;

Here is a functional example of calling java script within a VBA Word Project however I am having trouble modifying the example below with above java script function getcookie that i need.

NOTE for the below example to work you must add the Microsoft Script Control 1.0 reference object library.

Public Sub x()
     Dim o As New ScriptControl
     o.Language = "JScript"
     With o
         .AddCode "function x(a,b) {return 'the answer is:' +(a+b);}"
         Debug.Print .Run("x", 1, 2)
     End With
 End Sub
[ fanpages ]
Consultant (Development Team Lead, Senior Support Engineer, and Technical Test Leader)

Our community of experts have been thoroughly vetted for their expertise and industry experience.

Join our community to see this answer!
Unlock 1 Answer and 16 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 16 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros