본문 바로가기

카테고리 없음

urlencode / urldecode Excel VBA

Function ENCODEURL(varText As Variant, Optional blnEncode = True)

Static objHtmlfile As Object

    If objHtmlfile Is Nothing Then

      Set objHtmlfile = CreateObject("htmlfile")

      With objHtmlfile.parentWindow

        .execScript "function encode(s) {return encodeURIComponent(s)}", "jscript"

      End With

    End If

    If blnEncode Then

      ENCODEURL = objHtmlfile.parentWindow.encode(varText)

    End If

End Function


Function DECODEURL(varText As Variant, Optional blnEncode = True)

Static objHtmlfile As Object

    If objHtmlfile Is Nothing Then

      Set objHtmlfile = CreateObject("htmlfile")

      With objHtmlfile.parentWindow

        .execScript "function decode(s) {return decodeURIComponent(s)}", "jscript"

      End With

    End If

    If blnEncode Then

      DECODEURL = objHtmlfile.parentWindow.decode(varText)

    End If

End Function