View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Carim Carim is offline
external usenet poster
 
Posts: 510
Default macro to download a csv file

Hi,

As an example, here is the download of csv related to Yahoo stock
quotes ...

Sub GetYQuotes()
Base01 = "http://finance.yahoo.com/d/quotes.csv?s="
Base02 = "&f=sl1d1t1c1ohgv&e=.csv"
sURL = ""
SymString = ""

LastRow = Cells(65536, 1).End(xlUp).Row

For i = 1 To LastRow
SymString = SymString & Cells(i, 1) & " "
Next i
sURL = Base01 & SymString & Base02
Workbooks.Open sURL
Set rngSource = Cells(1).CurrentRegion
x = rngSource.Rows.Count
y = rngSource.Columns.Count
With ThisWorkbook.Sheets(1)
Set rngDest = Range(.Cells(1, 1), .Cells(x, y))
End With
rngDest.Value = rngSource.Value
ActiveWorkbook.Close SaveChanges:=False
End Sub

HTH
Carim