Consulting

Results 1 to 4 of 4

Thread: "object expected" suddenly popping up

  1. #1

    "object expected" suddenly popping up

    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.

  2. #2
    Knowledge Base Approver VBAX Guru GTO's Avatar
    Joined
    Sep 2008
    Posts
    3,368
    Location
    Quote Originally Posted by Sebastian H View Post
    I dug out an old macro which worked well three years ago, but this time it gets stuck in the ScriptEngine.Run line: ...
    This: ScriptEngine.AddCode "function encode(str) {return encodeHTMLComponent(str);}"
    Needs to be: ScriptEngine.AddCode "function encode(str) {return encodeURIComponent(str);}"

    Does that fix it?

    Mark

  3. #3
    Quote Originally Posted by GTO View Post
    Does that fix it?
    Yes! Thank you Mark!

    I don't understand what happened here, because I did use this macro successfully before, and I thought this was the latest version. But anyway, I'm happy it's working now!

  4. #4
    Knowledge Base Approver VBAX Guru GTO's Avatar
    Joined
    Sep 2008
    Posts
    3,368
    Location
    You are most welcome and glad it was an easy fix

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •