getElementsByTagname
Sounds like you have a timing problem - the table you need hasn't yet been
rendered when you try to get a reference to it.
Try replacing your "wait loop" with this:
Do While ie.document.readyState < "complete"
DoEvents
Loop
Tim
"senderj" wrote in message
...
Thank you for all the replies. My final coding looks like this, but
with occasional problem:
Sub Get_page3(conn)
Set ie = CreateObject("InternetExplorer.Application")
With ie
.Visible = False
.Navigate conn
Do Until Not .Busy
DoEvents
Loop
End With
Set doc_tables = ie.document.getElementsByTagname("table")
Set tab_rows = doc_tables(7).Rows
nRow = 0
For Each rr In tab_rows
If nRow = 0 Then 'skip header row
Else
cc = 0
For Each cel In rr.Cells
Selection.Offset(nRow - 1, cc).NumberFormat =
"General"
Selection.Offset(nRow - 1, cc).Value = cel.innertext
cc = cc + 1
Next
End If
nRow = nRow + 1
Next
Selection.Offset(tab_rows.Length - 1, 0).Select
End Sub
It is called by another macro 4 times, 1 for each page I want.
Sometimes it runs alright from first to last without problem.
Sometimes it stops in one of the page with "object variable or with
block variable not set" at the "Set tab_rows = doc_tables(7).Rows"
statement. But after entering debug mode, if I click Run, it continues
to run without the problem. Any idea?
|