我在Web上有XML数据。这些都是价格的价格数据,在游戏项目:Excel VBA从XML Web查询返回多个单元格的值
https://api.eve-central.com/api/marketstat?regionlimit=10000002&typeid=34
调用的函数来得到单值(例如最高买入顺序):
A B
1 ItemID buy/max
2 34 =ImportXML("https:// ... &typeid=34", "//buy/max")
3 35
功能样子:
Function ImportXML(url As String, query As String)
Dim document As MSXML2.DOMDocument60
Dim http As New MSXML2.XMLHTTP60
http.Open "GET", url, False
http.send
Set document = http.responseXML
ImportXML = document.SelectSingleNode(query).nodeTypedValue
End Function
这对一个值是可以的。如果我有500件物品,获取数据的时间非常长。 要填充多个单元(在这种情况下只有两个),我们需要通过添加& typeid的修改输入链接= 35:
https://api.eve-central.com/api/marketstat?regionlimit=10000002&typeid=34&typeid=35
有了这种联系,我可以得到两个数值为MSGBOX。但我需要处理这些数据,所以我需要在单元格B3。 现在的代码如下所示:
Function ImportXML(url As String, query As String)
Dim document As MSXML2.DOMDocument60
Dim http As New MSXML2.XMLHTTP60
http.Open "GET", url, False
http.send
Set document = http.responseXML
Dim R As Integer
Dim C As Integer
R = ActiveCell.Row '<- these variables are for changing'
C = ActiveCell.Column '<- output cell'
Set xmlNodeList = document.SelectNodes(query)
For Each xmlNode In xmlNodeList
Cells(R, C) = xmlNode.nodeTypedValue '<- THIS LINE CAUSE AN ERROR'
'MsgBox xmlNode.nodeTypedValue <- if that line is active I got correct result'
R = R + 1 'but in MsgBox'
Next xmlNode
End Function
当我试图从查询数据写入到细胞中存在的问题。 我试图做到的,是相似的行为IMPORTXML功能从谷歌表的Web服务。 我没有Excel 2013,所以我不能使用WEBSERVICE函数或FILTERXML和XPath。 我从来没有在VBA代码。 如果你可以把这里的最终代码,我将不胜感激。