I have API which gives me the stock price based on constructed URL with token and symbol,this API returns is web based and returns XML/JSON format data in <root></root>
and data in it. Below is an example.
<root>
<n5323 type="float">31.35</n5323 >
<n3221 type="float">9.06</n3221 >
</root>
I would like to retrieve price in Excel using VBA (31.35
and 9.06
), please help me on this how to achieve. Not that the n5323
and n3221
are generated dynamically and are different every time.
My VBA code is as below
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://testserver/volume/daily?token=' + token$ + '&ticker='+Symbol$+'"
objXMLHTTP.Open "POST", strXMLSite, False
objXMLHTTP.send
objXMLDoc.LoadXML (objXMLHTTP.responseText)
Set objXMLNodexbrl = objXMLDoc.SelectSingleNode("root")
Set objXMLNodeDIIRSP = objXMLNodexbrl.SelectSingleNode("root")
Worksheets("Sheet1").Range("J1").Value = objXMLNodeDIIRSP.Text