Hey, anyone know how to read information off a website?
Basically i just want to create a VBA function (or VB6 if necessary) that'll get the current stock market value for a given stock code.
Printable View
Hey, anyone know how to read information off a website?
Basically i just want to create a VBA function (or VB6 if necessary) that'll get the current stock market value for a given stock code.
Thanks for all the replies, you useless buggers :D
Figured it out myself - have to use the Microsoft Internet Transfer control.
:D :DVB Code:
Private Function GetStockValue(StockCode As String) As Currency ' This gets the value of a stock from the ninemsn website On Error GoTo bugger ' Create the url from the stock code Dim StockUrl As String StockUrl = "http://investor.ninemsn.com.au/investor/shares/quotes/delayed.asp?cntry=au&code=" & StockCode ' Grab the webpage Dim WebPage As String WebPage = INETXFER.OpenURL(StockUrl) ' Find the part with the price Dim i As Long i = InStr(WebPage, "lastsale") If i = 0 Then GoTo bugger i = InStr(i, WebPage, "<tr>") If i = 0 Then GoTo bugger i = InStr(i, WebPage, "<td") + 1 If i = 0 Then GoTo bugger i = InStr(i, WebPage, "<td") If i = 0 Then GoTo bugger i = InStr(i, WebPage, ">") + 1 If i = 0 Then GoTo bugger ' grab the price GetStockValue = CCur(Val(Mid(WebPage, i, 20))) Exit Function bugger: GetStockValue = 0 End Function