extracting data from 2nd row onwards

May 31, 2011
Reaction score
hi , i am extracting a table from outlook. my code works fine but i just want to extract the 2nd row of data onwards. the reason for this is i dont need the whole table all i need is the data; hence the first row which contain the header is not needed. i am not sure how abt to do this ? any advice would be greatly appreciated. my codes are as followed :

Sub getTableDataFromAccess()

Dim msg As Outlook.MailItem '
Dim i As Integer '
Dim j As Integer '
' ** requires project reference to Microsoft HTML Object Library
Dim webMsg As MSHTML.HTMLDocument '
Dim htable As MSHTML.HTMLTable '
Dim hrow As MSHTML.HTMLTableRow '
Dim hcell As MSHTML.HTMLTableCell '
Dim colTables As MSHTML.IHTMLElementCollection '
Dim colRows As MSHTML.IHTMLElementCollection '
Dim colCells As MSHTML.IHTMLElementCollection '
' ** requires project reference to Microsoft Excel library
Dim exc As Excel.Application '
Dim wb As Excel.Workbook '
Dim ws As Excel.Worksheet '

Set exc = CreateObject("Excel.Application")
Set wb = exc.Workbooks.Add '
Set ws = wb.Sheets(1) '

Set webMsg = Application.ActiveInspector.HTMLEditor

Set colTables = webMsg.getElementsByTagName("table")

Set htable = colTables.Item(, 1)

Set colRows = htable.rows

For Each hrow In colRows

i = hrow.RowIndex + 3 ' 4 is offset, change as needed to' adjust the blank rows at the top in EXCEL
Set colCells = hrow.cells

For Each hcell In colCells
j = hcell.cellIndex + 1
ws.cells(i, j) = Trim(hcell.innerText)

exc.Visible = True

End Sub

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question