0

I am trying to run a Javascript routine from within my VBA program as I am no longer able to use the HTML page.

Here is my code so far.

Private Sub objItems_ItemAdd(ByVal Item As Object)

    Dim jsObj As New ScriptControl

    'Define Scripting Language
    jsObj.Language = "JScript"
    With jsObj
        .AddCode "http://www.googleadservices.com/pagead/conversion.js"
        .Run "www.googleadservices.com/pagead/conversion/1027074920/?
label=U7DGCIzijF0Q6Nbf6QM&guid=ON&script=0"
    End With

    MsgBox "Message Subject: " & Item.Subject & vbCrLf & "Message Sender: " 
& Item.SenderName



'    <!-- Google Code for Registration Conversion Page -->

'    <script type="text/javascript">
'    /* <![CDATA[ */
'    var google_conversion_id = 1027074920;
'    var google_conversion_language = "en";
'        var google_conversion_format = "3";
'        var google_conversion_color = "ffffff";
'        var google_conversion_label = "U7DGCIzijF0Q6Nbf6QM";
'        var google_remarketing_only = false;
'        /* ]]> */
'    </script>
'    <script type="text/javascript" 
     src="//www.googleadservices.com/pagead/conversion.js">
'    </script>
'    <noscript>
'        <div style="display:inline;">
'            <img height="1" width="1" style="border-style:none;" alt="" 
          src="//www.googleadservices.com/pagead/conversion/1027074920/?
       label=U7DGCIzijF0Q6Nbf6QM&amp;guid=ON&amp;script=0"/>
'        </div>
'    </noscript>

End Sub

The commented out lines at the bottom of the sub are the lines from my web page that I am trying to duplicate.

braX
  • 11,506
  • 5
  • 20
  • 33
rtemen
  • 137
  • 4
  • 17
  • JScript doesn't support most of the modern JavaScript features https://stackoverflow.com/questions/135203/whats-the-difference-between-javascript-and-jscript – Slai Feb 11 '18 at 01:34

1 Answers1

0

I recommend the following.

Save your file to HTML.

Run this code to run it from VBA. It will run your file via Internet Exploder object.

Dim IE As Object

' Create InternetExplorer Object
Set IE = CreateObject("InternetExplorer.Application")

' You can uncoment Next line To see form results
' IE.Visible = False

IE.Navigate "yourlocalfilename"

' Statusbar
Application.StatusBar = "www.excely.com is loading. Please wait..."

' Wait while IE loading...
Do While IE.Busy
    Application.Wait DateAdd("s", 1, Now)
Loop
Ctznkane525
  • 7,297
  • 3
  • 16
  • 40
  • I started to look at this type of option at first. There are several reasons that I decided NOT to proceed with this. I do not have IE on my system. This html page is now divorced from the rest of the process, so I do not want to rely on it or have to maintain it. I do not want to have to wait on the page to load and then immediately close it. Therefore, I was looking for this solution where I do not need to rely on any web page(s). Thanks, – rtemen Feb 11 '18 at 03:38