PDA

View Full Version : Solved: extract data from website to excel



asdzxc
05-10-2012, 06:33 AM
In I1, put formula =TEXT(J1)
In J1 ,put ^DJI,say. What's wrong with the following code ,plse?
With Worksheets("Sheet1").QueryTables.Add(Connection:= _ "URL;http://ichart.finance.yahoo.com/table.csv?s=" & Cells(1, "I")&a=08&b=13&c=2011&d=06&e=6&f=2013&g=w&ignore=.xlsx"

Tinbendr
05-12-2012, 11:25 AM
Can you show us the direct link?

Tinbendr
05-12-2012, 12:20 PM
I think I got it. You had left the Destination range off, and there was a missing quote.

With Worksheets("Sheet2").QueryTables.Add(Connection:= _
"URL;http://ichart.finance.yahoo.com/table.csv?s=" _
& Sheet2.Cells(1, "I").Value & "&a=08&b=13&c=2011&d=06&e=6&f=2013&g=w&ignore=.csv", _
Destination:=Sheet2.Range("a1"))
I tried it without the qualified range (Sheet2.Cells(1, "I").Value vs Cells(1, "I") ), but it would error out.

I couldn't get the xlsx extension to work either,

HTH

asdzxc
05-13-2012, 06:47 PM
On Error Resume Next
ThisWorkbook.Connections(1).Delete
Err.Clear: On Error Goto 0
With Worksheets("Sheet1").QueryTables.Add(Connection:= _
"URL;http://ichart.finance.yahoo.com/table.csv?s=^STI&a=08&b=13&c=2011&d=06&e=6&f=2013&g=w&ignore=.xlsx _
, Destination:=Range("$A$1"))
.Name = _
"MyData"
.FieldNames = True
.RowNumbers = False
.FillAdjacentFormulas = False
.PreserveFormatting = True
.RefreshOnFileOpen = False
.BackgroundQuery = True
.RefreshStyle = 0
.SavePassword = False
.SaveData = True
.AdjustColumnWidth = True
.RefreshPeriod = 0
.WebSelectionType = xlSpecifiedTables
.WebFormatting = xlWebFormattingNone
.WebTables = "4"
.WebPreFormattedTextToColumns = True
.WebConsecutiveDelimitersAsOne = True
.Refresh BackgroundQuery:=False
End With

Tinbendr
05-14-2012, 07:23 AM
With Worksheets("Sheet1").QueryTables.Add(Connection:= _
"URL;http://ichart.finance.yahoo.com/table.csv?s=" & _
Worksheets("Sheet1").Range("J1").Value & "&a=08&b=13&c=2011&d=06&e=6&f=2013&g=w&ignore=.xlsx" _
, Destination:=Worksheets("Sheet1").Range("$A$1"))

asdzxc
05-14-2012, 08:24 PM
Thank you