Lee2014
05-03-2014, 10:04 PM
Hi,
Thanks in advance for your assistance, I appreciate it.
I have a macro which fetches the closing (last) price of an Australian share and it functions very well.
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.
I am struggling to do this myself because the HTML from the ASX website presents the "close" data in a different way to the open, high, low & volume data. Unfortunately I cannot post a link to the ASX website but if you google "ASX WOW" it will take you to the Woolworths page on the ASX website.
Here is the code I currently have:
Public Function close_price(code As String)
html_source = ShowHTML(code)
checkval = "<td class=""last"">"
pos_check = InStr(1, html_source, checkval, vbTextCompare) + Len(checkval)
Length = Len(html_source) - pos_check + 1
html_source = Right(html_source, Length)
pos_end = InStr(1, html_source, "</td>", vbTextCompare) - 1
htm = Left(html_source, pos_end)
If IsNumeric(htm) Then
htm = CDbl(htm)
Else
htm = "N/A"
End If
close_price = htm
End Function
Private Function ShowHTML(code As String)
strURL = "WEBSITE URL GOES HERE, I CANT POST A URL TO THIS FORUM" & code
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
Here is an extract of the HTML code from the ASX website where it presents all the data I need:
<td class="last">36.600</td>
<td style="white-space: nowrap;" class="change indicator">0.22%</td>
<td>36.550</td>
<td>36.600</td>
<td>36.600</td>
<td>36.800</td>
<td>36.400</td>
<td>2,357,945</td>
The red lines above are bid, offer, open, high, low and volume (in that order). The blue line is the closing/last price.
I get the "last" price by searching for "<td class="last">" however this obviously won't work for the others because they are prefixed with a very generic string "<td>".
I hope you understand my problem, it was very difficult to articulate.
Thanks so much!
Thanks in advance for your assistance, I appreciate it.
I have a macro which fetches the closing (last) price of an Australian share and it functions very well.
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.
I am struggling to do this myself because the HTML from the ASX website presents the "close" data in a different way to the open, high, low & volume data. Unfortunately I cannot post a link to the ASX website but if you google "ASX WOW" it will take you to the Woolworths page on the ASX website.
Here is the code I currently have:
Public Function close_price(code As String)
html_source = ShowHTML(code)
checkval = "<td class=""last"">"
pos_check = InStr(1, html_source, checkval, vbTextCompare) + Len(checkval)
Length = Len(html_source) - pos_check + 1
html_source = Right(html_source, Length)
pos_end = InStr(1, html_source, "</td>", vbTextCompare) - 1
htm = Left(html_source, pos_end)
If IsNumeric(htm) Then
htm = CDbl(htm)
Else
htm = "N/A"
End If
close_price = htm
End Function
Private Function ShowHTML(code As String)
strURL = "WEBSITE URL GOES HERE, I CANT POST A URL TO THIS FORUM" & code
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
Here is an extract of the HTML code from the ASX website where it presents all the data I need:
<td class="last">36.600</td>
<td style="white-space: nowrap;" class="change indicator">0.22%</td>
<td>36.550</td>
<td>36.600</td>
<td>36.600</td>
<td>36.800</td>
<td>36.400</td>
<td>2,357,945</td>
The red lines above are bid, offer, open, high, low and volume (in that order). The blue line is the closing/last price.
I get the "last" price by searching for "<td class="last">" however this obviously won't work for the others because they are prefixed with a very generic string "<td>".
I hope you understand my problem, it was very difficult to articulate.
Thanks so much!