ancestetta
Programmer
Hey y'all,
I'm a little vba beginner, and want to read out the content of a table from an HTML page, and copy only the cells of the second row to excel.
I searched for long time in google, and finally I could write the following code. This script allows me to copy ALL rows, but I need only the second row. Could some body help me??
Thanks:
Sub test()
Set objExcel = ActiveWindow.ActiveSheet
Dim objIE
Dim varTables, varTable
Dim varRows, varRow
Dim varCells, varCell
Dim lngRow
Dim lngColumn
Dim strBuffer
Dim VINS
Dim URL
URL = "xxxxxxx"
Set objIE = CreateObject("InternetExplorer.Application")
With objIE
.Navigate URL
End With
While objIE.Busy
Wend
While objIE.Document.ReadyState <> "complete"
Wend
Set varTables = objIE.Document.All.tags("table")
For Each varTable In varTables
Set varRows = varTable.Rows
lngRow = 2 'This will be the first output row
For Each varRow In varRows
Set varCells = varRow.Cells
lngColumn = 1 'This will be the output column
For Each varCell In varCells
objExcel.Cells(lngRow, lngColumn) = varCell.innerText
lngColumn = lngColumn + 1
Next
lngRow = lngRow + 1
Next
Next
End Sub
I'm a little vba beginner, and want to read out the content of a table from an HTML page, and copy only the cells of the second row to excel.
I searched for long time in google, and finally I could write the following code. This script allows me to copy ALL rows, but I need only the second row. Could some body help me??
Thanks:
Sub test()
Set objExcel = ActiveWindow.ActiveSheet
Dim objIE
Dim varTables, varTable
Dim varRows, varRow
Dim varCells, varCell
Dim lngRow
Dim lngColumn
Dim strBuffer
Dim VINS
Dim URL
URL = "xxxxxxx"
Set objIE = CreateObject("InternetExplorer.Application")
With objIE
.Navigate URL
End With
While objIE.Busy
Wend
While objIE.Document.ReadyState <> "complete"
Wend
Set varTables = objIE.Document.All.tags("table")
For Each varTable In varTables
Set varRows = varTable.Rows
lngRow = 2 'This will be the first output row
For Each varRow In varRows
Set varCells = varRow.Cells
lngColumn = 1 'This will be the output column
For Each varCell In varCells
objExcel.Cells(lngRow, lngColumn) = varCell.innerText
lngColumn = lngColumn + 1
Next
lngRow = lngRow + 1
Next
Next
End Sub