Originally Posted by
Lee2014
I would like to create an additional 4 macros that fetch the opening price, high of the day, low of the day and volume for the day.
Well, I haven't quite done that (I didn't read your message fully before getting into the nitty gritty), instead I wrote a udf to get you the following 7 prices:
Last Bid Offer Open High Low Volume
It gets all 7 values in one visit to the site and you can see them all on a sheet in a horizontal row if you array-enter (Ctrl+Shift+Enter, not just Enter) the formula all at once in a range of cells 1 row high and 7 columns wide.
If you need them vertically I can tweak the macro or you can use TRANSPOSE.
Using 4 different UDFs (macros) will take about 4 times as long.
I also didn't read or follow your instructions on how to get to the site via Google, as a consequence I used a different web page of the Asx site to get the data from, so I have written 2 udfs, one to get data from the page you suggested (ThePrices) and one called ThePrices2 which uses the equityPrices page which is a little easier to get the data from rather than the companyInfo page. There is documentation among the comments in the code.
You only need one of these two udfs.
If you want the Open alone you can use the likes of (you don't need to array-enter these):
=INDEX(ThePrices(D13),4)
where D13 contains the company symbol, or use the company symbol in the formula if you wish:
=INDEX(ThePrices("WOW"),4)
For the high, low and volume you'd change the 4 to 5, 6 and 7 respectively.
If you want, I/you could tweak the udf to output only the 4 values you want. This would be quicker than fetching those 4 values with 4 separate INDEX formulae.
Here's the code and I've attached a sample workbook.
Public Function ThePrices(code As String)
'use with http://www.asx.com.au/asx/research/companyInfo.do?by=asxCode&asxCode= in the ShowHTML function
Dim myPrices(0 To 6)
html_source = ShowHTML(code)
checkval = "<td class=""last"">"
html_source = Split(html_source, checkval)(1)
html_source = Left(html_source, 600) 'temporary line, needs refining.
html_source = Application.Trim(Application.Clean(html_source))
yyy = Split(html_source, "</td> <td>")
yyy(0) = Split(yyy(0), "</td>")(0)
yyy(6) = Split(yyy(6), "</td>")(0)
For i = 0 To 6
If IsNumeric(yyy(i)) Then myPrices(i) = CDbl(yyy(i)) Else myPrices(i) = "N/A"
Next i
ThePrices = myPrices
End Function
Private Function ShowHTML(code As String)
'strURL = "http://www.asx.com.au/asx/markets/equityPrices.do?by=asxCodes&asxCodes=" & code 'use with ThePrices2
strURL = "http://www.asx.com.au/asx/research/companyInfo.do?by=asxCode&asxCode=" & code 'use with ThePrices
strError = ""
Dim oXMLHTTP As MSXML2.XMLHTTP
Set oXMLHTTP = New MSXML2.XMLHTTP
strResponse = ""
With oXMLHTTP
.Open "POST", strURL, False
.send ""
strResponse = .responseText
End With
ShowHTML = strResponse
End Function
Public Function ThePrices2(code As String)
'use with http://www.asx.com.au/asx/markets/equityPrices.do?by=asxCodes&asxCodes= in the ShowHTML function
Dim myPrices(0 To 6)
html_source = ShowHTML(code)
checkval = "<td class=""last"">"
html_source = Split(html_source, checkval)(1)
html_source = Left(html_source, 500) 'temporary line, needs refining.
html_source = Application.Clean(html_source)
yyy = Split(html_source, "</td><td>")
yyy(0) = Split(yyy(0), "</td>")(0)
yyy(6) = Split(yyy(6), "</td>")(0)
For i = 0 To 6
If IsNumeric(yyy(i)) Then myPrices(i) = CDbl(yyy(i)) Else myPrices(i) = "N/A"
Next i
ThePrices2 = myPrices
End Function