【问题标题】:Strange XML map run-time error with Excel VBAExcel VBA 出现奇怪的 XML 映射运行时错误
【发布时间】:2013-10-12 16:06:41
【问题描述】:

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.Refresh?
  • 对不起,调试错误时不是Map.DataBinding.LoadSettings

标签: xml excel vba data-binding


【解决方案1】:

尝试改变

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

【讨论】:

  • 感谢您的建议 - 第一个仍然会产生相同的运行时错误,第二个会产生“运行时错误 9”(子脚本超出范围)错误,但不幸的是
【解决方案2】:

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

【讨论】:

    猜你喜欢
    • 2017-06-28
    • 2011-02-07
    • 2014-12-20
    • 2017-01-03
    • 2016-07-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-01-21
    相关资源
    最近更新 更多