Sebastian H
03-04-2016, 01:56 AM
I dug out an old macro which worked well three years ago, but this time it gets stuck in the ScriptEngine.Run line:
Function encodeHTML(str As String)
' found at http://stackoverflow.com/questions/218181/how-can-i-url-encode-a-string-in-excel-vba; replaced "URL" by "HTML"
Dim ScriptEngine As ScriptControl
Set ScriptEngine = New ScriptControl
ScriptEngine.Language = "JScript"
ScriptEngine.AddCode "function encode(str) {return encodeHTMLComponent(str);}"
Dim encoded As String
encoded = ScriptEngine.Run("encode", str) ' <-- error "object expected"
encodeHTML = encoded
End Function
Where does it expect the object? The obvious assumption is ScriptEngine, but if that weren't an object, the .AddCode method wouldn't work, before.
Function encodeHTML(str As String)
' found at http://stackoverflow.com/questions/218181/how-can-i-url-encode-a-string-in-excel-vba; replaced "URL" by "HTML"
Dim ScriptEngine As ScriptControl
Set ScriptEngine = New ScriptControl
ScriptEngine.Language = "JScript"
ScriptEngine.AddCode "function encode(str) {return encodeHTMLComponent(str);}"
Dim encoded As String
encoded = ScriptEngine.Run("encode", str) ' <-- error "object expected"
encodeHTML = encoded
End Function
Where does it expect the object? The obvious assumption is ScriptEngine, but if that weren't an object, the .AddCode method wouldn't work, before.