【发布时间】:2021-09-03 14:25:09
【问题描述】:
Excel VBA 中有没有一种方法可以通过指定字符集来解码 url?我对我的计算机没有管理员权限,这意味着我无法安装外部软件包,因此我需要一个针对 Excel VBA(或本机环境)的独立解决方案。
我找到了一个链接here 来解码一个url(下面的代码供参考);但是,它不适用于解码为韩文字符。我收到以下错误:运行时错误“-2147352319 (80020101)”对象“JScriptTypeInfo”的“解码”方法失败。
我试图为 Excel VBA 找到解决方案没有成功。 (我运行的是 Windows 10;Microsoft Excel 365,版本 2107;添加了韩语语言包;区域设置 -- 非 unicode 程序的语言:韩语(韩国)。
这是正确结果的示例(使用 charset 'Korean (euc-kr)' here 正确解码/编码):
- 编码:%28%C1%D6%29%B7%B9%B0%ED%C4%DA%B8%AE%BE%C6
- 使用“euc-kr”解码:(주)레고코리아
以下代码参考:
Sub Testing()
Debug.Print UriDecode("%28%C1%D6%29%B7%B9%B0%ED%C4%DA%B8%AE%BE%C6")
End Sub
Function UriDecode(strText As String)
Static objHtmlFile As Object
If objHtmlfile Is Nothing Then
Set objHtmlfile = CreateObject("htmlfile")
objHtmlfile.parentWindow.execScript "function decode(s) {return decodeURIComponent(s)}", "jscript"
End If
UriDecode = objHtmlfile.parentWindow.decode(strText)
End Function
【问题讨论】:
标签: excel vba character-encoding urldecode