Skip to content Skip to sidebar Skip to footer

64 Bit Excel Vba To Call A Javascript Function

I need to use a VBA ScriptControl object to call a JavaScript function , but it gave me a 'Class Not Registered' error. I have added Microsoft Script Control 1.0 from Tools->Re

Solution 1:

There's no need for a ScriptControl object: you can use XMLHTTP and VBA-JSON.

For example:

PublicSub Tester()

    'Import the "JsonConverter.bas" file from '     https://github.com/VBA-tools/VBA-JSON'and add a reference to the Microsoft Scripting Runtime libraryDim http AsObject, JSON AsObject, i AsInteger, o AsObject, k

    Set http = CreateObject("MSXML2.XMLHTTP")
    http.Open "GET", "https://www.alphavantage.co/query?" & _
          "function=CURRENCY_EXCHANGE_RATE&from_currency=USD" & _
          "&to_currency=JPY&apikey=demo", False

    http.Send

    Debug.Print http.responseText
    Debug.Print "-----------------------------------"Set JSON = ParseJson(http.responseText)

    Set o = JSON("Realtime Currency Exchange Rate")
    ForEach k In o.keys
        Debug.Print k, o(k)
    Next k

EndSub

Post a Comment for "64 Bit Excel Vba To Call A Javascript Function"