Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save muhdkhokhar/f25ccedc76a1d8fc7876f0a903e45185 to your computer and use it in GitHub Desktop.
Save muhdkhokhar/f25ccedc76a1d8fc7876f0a903e45185 to your computer and use it in GitHub Desktop.
Sub RunJavaScript()
' Declare the ScriptControl object
Dim sc As Object
Set sc = CreateObject("MSScriptControl.ScriptControl")
' Set the language to JavaScript
sc.Language = "JScript"
' Write the JavaScript code you want to execute
Dim jsCode As String
jsCode = "function add(a, b) { return a + b; }"
' Add the code to the ScriptControl
sc.AddCode jsCode
' Run the JavaScript function and get the result
Dim result As Variant
result = sc.Run("add", 5, 3)
' Display the result
MsgBox "The result of adding 5 and 3 is: " & result
End Sub
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment