How can I URL encode a string in Excel VBA?

后端 未结 15 2323
闹比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:04

    Similar to Michael-O's code, only without need to reference (late bind) and with less one line .
    * I read, that in excel 2013 it can be done more easily like so: WorksheetFunction.EncodeUrl(InputString)

    Public Function encodeURL(str As String)
        Dim ScriptEngine As Object
        Dim encoded As String
    
        Set ScriptEngine = CreateObject("scriptcontrol")
        ScriptEngine.Language = "JScript"
    
        encoded = ScriptEngine.Run("encodeURIComponent", str)
    
        encodeURL = encoded
    End Function
    

提交回复
热议问题