VBA pull XML data to Excel

前端 未结 1 1425
既然无缘
既然无缘 2020-12-01 23:30

A tricky question on VBA Please see pictures for your accurate view of the problem

If you type on Google \"SEC EDGAR\"

相关标签:
1条回答
  • 2020-12-01 23:48

    You should still try and learn about Microsoft XML Core Services (MSXML) but to get you started you can start with the following and modify it as needed. If you need a lot of values it would be worth looping the ChildNodes of objXMLNodexbrl as a lot of the nodes also seem to be duplicated.

    instead of using <Current> in my sample I used an actual value for us-gaap:DebtInstrumentInterestRateStatedPercentage (the one you had circled in your question)

    Sub GetNode()
    Dim strXMLSite As String
    Dim objXMLHTTP As MSXML2.XMLHTTP
    Dim objXMLDoc As MSXML2.DOMDocument
    Dim objXMLNodexbrl As MSXML2.IXMLDOMNode
    Dim objXMLNodeDIIRSP As MSXML2.IXMLDOMNode
    
    Set objXMLHTTP = New MSXML2.XMLHTTP
    Set objXMLDoc = New MSXML2.DOMDocument
    
    strXMLSite = "http://www.sec.gov/Archives/edgar/data/10795/000119312513456802/bdx-20130930.xml"
    
    objXMLHTTP.Open "POST", strXMLSite, False
    objXMLHTTP.send
    objXMLDoc.LoadXML (objXMLHTTP.responseText)
    
    Set objXMLNodexbrl = objXMLDoc.SelectSingleNode("xbrl")
    
    Set objXMLNodeDIIRSP = objXMLNodexbrl.SelectSingleNode("us-gaap:DebtInstrumentInterestRateStatedPercentage")
    
    Worksheets("Sheet1").Range("A1").Value = objXMLNodeDIIRSP.Text
    End Sub
    
    0 讨论(0)
提交回复
热议问题