奇怪的XML映射运行时错误与Excel VBA



Excel VBA 中的 XML 映射遇到一些问题,该映射会自动查询 API 并在将值输入特定单元格后检索其数据。映射工作正常,刷新 XML 映射并将查询数据检索到另一个所需的单元格中,但尽管取得了成功,它仍然会在 VBA 中强制出现运行时错误。

给出的运行时错误是"-2147217376 (80041020)"

"指定资源的下载失败。"

这是我在 VBA 中的代码。我已经更改了网站的示例,但查询的格式是相同的。

If Target.Column = 6 And (Target.Row >= 1 And Target.Row <= 10000) Then
Dim CellVariable As String: CellVariable = Target.Value
End If
Dim Map As XmlMap
Set Map = ActiveWorkbook.XmlMaps(1)
Map.DataBinding.LoadSettings "http://example.website.com/api/question?name=" & CellVariable & "&api_key=xxxxxxxxx&format=xml"
On Error Resume Next
Map.DataBinding.Refresh
On Error Resume Next

有没有办法以某种方式覆盖此错误? On Error Resume Next似乎没有做到这一点。任何建议不胜感激!

尝试更改

Map.DataBinding.LoadSettings "http://example.website.com/api/question?name=" & CellVariable & "&api_key=xxxxxxxxx&format=xml"

对此(添加的括号):

Map.DataBinding.LoadSettings("http://example.website.com/api/question?name=" & CellVariable & "&api_key=xxxxxxxxx&format=xml")

或者这个(不同的方法):

urlstr = "http://example.website.com/api/question?name=" & CellVariable & "&api_key=xxxxxxxxx&format=xml"
ThisWorkbook.XmlMaps(Map).Import urlStr

我发现当Excel无法登录网页时出现此错误。 我找到的唯一解决方案是浏览到 Internet Explorer 中的位置,输入我的凭据,然后告诉 Internet Explorer 记住我的登录信息。这将工作一段时间,直到 cookie 过期或其他什么,我去再次登录。

最新更新