In my previous question (everything needed is on this question; the link is here for the sake of completeness and measure) i ask for a way to pull XML data to Excel from a Web location. The code i received (courtesy of user2140261) as an answer lies here:
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
But every company has a different XML Instance Document, and every time period a company publishes a different XML Instance Document (e.g. quarterly, annually). So these documents can be accessed in different web locations.
Now in the previous procedure we can see we only need to use the statement
strXMLSite = "http://www.sec.gov/Archives/edgar/data/10795/000119312513456802/bdx-20130930.xml"
...but this is when we know beforehand that we want data from one specified location in the Web
What if we want to pull some data for these 4 different locations depicted by an asterisk(*) in the image below
How could we actually input our "coordinates" in Excel let's say in one of our userforms/cells for example and then make VBA "navigate/crawl" there just by using these coordinates just as we are navigating there with a browser?
The coordinates that we input can be:
- A Stock Ticker (e.g. TSLA for Tesla Motors)
- A type of files for example 10-Q's
You can pick the type of files in these links for BDX and ANN respectively:
Below we have 2 web locations for the Instance Document locations of BDX company and 2 for ANN company
BDX Company
http://www.sec.gov/Archives/edgar/data/10795/000119312514042815/bdx-20131231.xml http://www.sec.gov/Archives/edgar/data/10795/000119312513318898/bdx-20130630.xml
ANN Company
http://www.sec.gov/Archives/edgar/data/874214/000087421413000036/ann-20131102.xml http://www.sec.gov/Archives/edgar/data/874214/000087421413000027/ann-20130803.xml
How could we pull from an XML element that is existent in all the four instance documents for example us-gaap:CommonStockValue
by simply giving VBA the
- Stock Ticker
- The document type (10-K, 10-Q)
Can it be done with the use of Microsoft XML Core Services (MSXML) or we require some other Library too?
You can see how impractical it is to fire this code thousand of times and every time copy the URL from the Web Browser to the strXMLSite as a String value....