import data from website

  • Thread starter Thread starter Maximilian Harmstorf
  • Start date Start date
M

Maximilian Harmstorf

Hi all,
I need to get a solution for following problem.

I need to extract a table from a website, like this
http://www.cbot.com/cbot/pub/page/0,3181,1213,00.html and get it into a
useful format
Already tried it with the usual "import website" functions in Excel, but
neither is it working everytime, nor is it possible to add the data instead
of overwriting them all the time.

At the same time I would prefer it to delete unused rows and cells in the
spreadsheet after the import, but this is a minor issue.

It would be nice, if the format could look like this in the end.

17-Sep 16-Sep 15-Sep
24964 25131 25519
27450 27350 27200
27450 27350 27200

Every help is appreciated & thanks in advance

brgds
Max
 
Sub GetQuotes()

CR = Chr(13)

Set ie = CreateObject("InternetExplorer.Application")
ie.Visible = True

URL = "http://www.cbot.com/cbot/pub/page/0,3181,1213,00.html"

'get web page
ie.Navigate2 URL
Do While ie.readyState <> 4
DoEvents
Loop

Do While ie.busy = True
DoEvents
Loop
Set cTable = ie.Document.getElementsByTagname("table")
'get all rows excep last row which contains the data
''Table starts at row 0, subtract two to ignore last row
ColCount = 1
For TableRow = 0 To (cTable(0).Rows.Length - 2)
Set TRow = cTable(0).Rows(TableRow)
RowCount = 1
For Each cell In TRow.Cells
Cells(RowCount, ColCount) = _
Trim(Replace(cell.innertext, CR, ""))
RowCount = RowCount + 1
Next cell
ColCount = ColCount + 1
Next TableRow

End Sub
 
Back
Top