I built some code to retrieve stock data from Yahoo as a CSV file, and it works fine. When I change the URL to the perfectly legal version that recalls minutewise data from Google instead, it fails on the
objHTTP.open "GET", strURL, False
statement.
The following code shows both URLs, although obviously only the final one is called. Both URLs work when posted into the address bar of a browser.
Can anyone explain why the call to Google's page won't Open?
option explicit
Dim objHTTP
dim strURL
dim objFile
dim objFSO
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objHTTP = CreateObject("MSXML2.XMLHTTP")
' WORKS:
strURL = "http://real-chart.finance.yahoo.com/table.csv?s=UPRO&a=04&b=21&c=2016&d=04&e=31&f=2016&g=d&ignore=.csv"
' DOES NOT WORK:
strURL = "www.google.com/finance/getprices?q=UPRO&i=60&p=20d&f=d,c,v,k,o,h,l&df=cpct&auto=0&ei=Ef6XUYDfCqSTiAKEMg"
objHTTP.open "GET", strURL, False
objHTTP.send
msgbox objHTTP.responseText
Set objFile = objFSO.CreateTextFile _
("Yahoo.csv", 2)
objFile.Write objHTTP.ResponseText
objFile.Close