Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/excel/26.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用VBA请求联机XML上的特定属性_Xml_Excel_Vba - Fatal编程技术网

使用VBA请求联机XML上的特定属性

使用VBA请求联机XML上的特定属性,xml,excel,vba,Xml,Excel,Vba,最近,我试图在VBA for excel中编写一个自定义函数,从Web服务获取股票信息。但是,生成的XML是这样编写的: <ComportamentoPapeis> <Papel Codigo="BOVA11" Nome="ISHARES BOVA CI" Ibovespa="" Data="29/05/2015 17:29:57" Abertura="52,04" Minimo="51,28" Maximo="52,24" Me

最近,我试图在VBA for excel中编写一个自定义函数,从Web服务获取股票信息。但是,生成的XML是这样编写的:

<ComportamentoPapeis>
<Papel Codigo="BOVA11" Nome="ISHARES BOVA CI" 
       Ibovespa="" Data="29/05/2015 17:29:57" 
       Abertura="52,04" Minimo="51,28" Maximo="52,24" 
       Medio="51,64" Ultimo="51,35" Oscilacao="-1,98"/>
</ComportamentoPapeis>
在这种特殊情况下,sName=BOVA11和sItem=Nome


有人知道出了什么问题吗?我已经在MSXML v6.0中引用了它。

atributes.getNamedItem(sItem.Text)
-在
属性中有一个输入错误

非常感谢!我花了好几个小时试图找出错误,结果被一个打字错误打败了!
    Function STOCK(sName As String, sItem As String, Optional sURL = "") 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://www.bmfbovespa.com.br/Pregao-" & _
                "Online/ExecutaAcaoAjax.asp?CodigoPapel="
    End If

    'open the request and send it
    oHttp.Open "GET", sURL & sName, False
    oHttp.Send

    'get the response as xml
    Set xmlResp = oHttp.responseXML

    ' get Item
    STOCK = xmlResp.SelectSingleNode("/ComportamentoPapeis/Papel"). _
                 Atrributes.getNamedItem(sItem).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:
    STOCK = CVErr(xlErrValue)
    GoTo CleanUp
End Function