Created
July 19, 2024 07:40
-
-
Save muhdkhokhar/f25ccedc76a1d8fc7876f0a903e45185 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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