I have been successfully running a VBA macro for several years that retrieves data from a website at http://ichart.finance.yahoo.com
It fetches data from that website with a formula "=StockCloseAdj(stock symbol, date)" and populates return info into the cell in my EXCEL spreadsheet.
About 1-2 weeks ago it stopped working and returns the argument as #VALUE!
I have attached a text version of the macro.
I tried manually debugging the code.
It appears to execute the line:
http.Open "GET", strURL, False
But crashes when it gets to:
http:send
This macro has been extremely valuable to me because I can use it to access the daily "Adj. Close" price for as many stocks as I want going back as many years as I want.
I'm not good at debugging, so it's possible that something other than the line I indicated above is causing the problem.
Can anyone help?
I'll also post in the macro text below in case their is a problem with my attachment:
Metsci
= = = = = = = = = = = = = = = = = = = = = = =
Function StockCloseAdj(strTicker As String, Optional dtDate As Variant)
' Date is optional - if omitted, use today. If value is not a date, throw error.
If IsMissing(dtDate) Then
dtDate = Date
Else
If Not (IsDate(dtDate)) Then
StockCloseAdj = CVErr(xlErrNum)
End If
End If
Dim dtPrevDate As Date
Dim strURL As String, strCSV As String, strRows() As String, strColumns() As String
Dim dbClose As Double
dtPrevDate = dtDate - 7
' Compile the request URL with start date and end date
strURL = "http://ichart.finance.yahoo.com/table.csv?s=" & strTicker & _
"&a=" & Month(dtPrevDate) - 1 & _
"&b=" & Day(dtPrevDate) & _
"&c=" & Year(dtPrevDate) & _
"&d=" & Month(dtDate) - 1 & _
"&e=" & Day(dtDate) & _
"&f=" & Year(dtDate) & _
"&g=d&ignore=.csv"
' Debug.Print strURL
Set http = CreateObject("MSXML2.XMLHTTP")
http.Open "GET", strURL, False
http.Send
strCSV = http.responseText
' Debug.Print strCSV
' The most recent information is in row 2, just below the table headings.
' The ? ? ? ? is the 1st entry index = 0
' The open price is the 2nd entry index = 1
' The high price is the 3rd entry index = 2
' The low price is the 4th entry index = 3
' The price close is the 5th entry index = 4
' The volume is the 6th entry index = 5
' The adjusted close is the 7th entry index = 6
strRows() = Split(strCSV, Chr(10)) ' split the CSV into rows
strColumns = Split(strRows(1), ",") ' split the relevant row into columns. 1 means 2nd row, starting at index 0
dbClose = strColumns(6) ' 6 means: 7th position, starting at index 0
' Debug.Print vbLf
' Debug.Print strRows(1)
' Debug.Print "dbClose: " & dbClose
StockCloseAdj = dbClose
Set http = Nothing
End Function
Bookmarks