0

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似乎没有成功。任何建议表示赞赏!

4

2 回答 2

0

尝试改变

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
于 2013-10-05T19:56:15.897 回答
0

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

于 2016-04-27T16:28:32.547 回答