從excel文檔查詢以從活動XML數據源進行更新(我無法編輯或更改)。使用Excel查詢在線XML文檔
從網站的XML代碼
<?xml version='1.0' encoding='utf-8'?>
<evec_api version="2.0" method="marketstat_xml">
<marketstat><type id="24692">
<buy><volume>58</volume><avg>187454397.24</avg><max>191102293.00</max><min>170620000.01</min><stddev>6655174.57</stddev><median>191000100.02</median><percentile>191102293.00</percentile></buy>
<sell><volume>66</volume><avg>211618794.64</avg><max>266968892.26</max><min>202896968.00</min><stddev>11782399.14</stddev><median>206970995.32</median><percentile>202896977.39</percentile></sell>
<all><volume>224</volume><avg>110889266.01</avg><max>266968892.26</max><min>0.99</min><stddev>30116759.19</stddev><median>186251523.01</median><percentile>0.99</percentile></all>
</type></marketstat>
</evec_api>
我的UDF的excel模塊代碼
Function GetPrice(sItemID As String, sItem As String, Optional sURL = "", Optional sSystem = "") As Variant
Dim oHttp As New MSXML2.XMLHTTP60
Dim xmlResp As MSXML2.DOMDocument60
Dim result As Variant
On Error GoTo EH
If sURL = "" Then
sURL = "http://api.eve-central.com/api/marketstat?typeid="
End If
If sSystem = "" Then
sSystem = "&usesystem=30000142"
End If
'open the request and send it
oHttp.Open "GET", sURL & sItemID & sSystem, False
oHttp.Send
'get the response as xml
Set xmlResp = oHttp.responseXML
' get Item
GetPrice = xmlResp.getElementsByTagName(sItem).Item(0).Text
' Examine output of these in the Immediate window
Debug.Print sName
Debug.Print xmlResp.XML
CleanUp:
On Error Resume Next
Set xmlResp = Nothing
Set oHttp = Nothing
Exit Function
EH:
GetPrice = CVErr(xlErrValue)
GoTo CleanUp
End Function
當試圖查詢=用getPrice(24692, 「//賣出/分鐘」)練成返回#值!錯誤。當查詢= GetPrice(24692,「賣」)將返回66211618794.64266968892.26202896968.0011782399.14206970995.32202896977.39 這似乎是來自銷售行的所有數據,當我正在尋找202896968.00與銷售行數據標籤下min以及buy標籤中的最大值來填充Excel文檔。