How can I URL encode a string in Excel VBA?

后端 未结 15 2212
闹比i
闹比i 2020-11-22 11:39

Is there a built-in way to URL encode a string in Excel VBA or do I need to hand roll this functionality?

15条回答
  •  执念已碎
    2020-11-22 12:14

    Since office 2013 use this inbuilt function here.

    If before office 2013

    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
    

    Add Microsoft Script Control as reference and you are done.

    Same as last post just complete function ..works!

提交回复
热议问题