I know it's a bit silly to load a js into VBA, but I need to load the libphonenumber library by Google to perform an analysis of a big bunch of phone numbers.
I tried to adapt the following code borrowed from here, but the compiled library is to big to be inserted into the Vba code.
Is there any way to load the .js library from a file instead? Thanks!
Function encodeURL(str As String)
Dim ScriptEngine As ScriptControl
Set ScriptEngine = New ScriptControl
ScriptEngine.Language = "JScript"
ScriptEngine.AddCode "function encode(str) {return encodeURIComponent(str);}"
Dim encoded As String
encoded = ScriptEngine.Run("encode", str)
encodeURL = encoded
End Function
UPDATE.
This should be a working code, but for some reason doesn't works:
Function loabdjs(x As String)
Dim fso As Scripting.FileSystemObject
Set fso = New Scripting.FileSystemObject
Dim script As String
Dim fs As Scripting.TextStream
''' CODE : "function encode(str) {return encodeURIComponent(str);}"
Set fs = fso.OpenTextFile("test.js", ForReading, False)
MsgBox ("Never reached this point")
script = fs.ReadAll
fs.Close
Dim ScriptEngine As ScriptControl
Set ScriptEngine = New ScriptControl
Dim output As String
ScriptEngine.Language = "JScript"
ScriptEngine.AddCode script
output = ScriptEngine.Run("encode", x)
loadjs = output
End Function
Any ideas?