Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
getElementsByTagname
I am writing a marco to put a html table into cells. I am able to
Set doc_tables = ie.Document.getElementsByTagname("table") Set tab_rows = doc_tables(7).getElementsByTagname("tr") But I hit an error when trying to Set tab_cells = tab_rows.getElementsByTagname("td") Where can I read more about this kind of coding? Is this called ActiveX object DOM? |
#2
Posted to microsoft.public.excel.programming
|
|||
|
|||
getElementsByTagname
Have you tried
Set doc_tables = ie.Document.getElementsByTagname("table") Set tab_cells = doc_tables(7).getElementsByTagname("td") Your line: Set tab_cells = tab_rows.getElementsByTagname("td") does not work because tab_rows is a collection of elements, not a single element. Set tab_cells = tab_rows(1).getElementsByTagname("td") (eg) should work. Tim "senderj" wrote in message ... I am writing a marco to put a html table into cells. I am able to Where can I read more about this kind of coding? Is this called ActiveX object DOM? |
#3
Posted to microsoft.public.excel.programming
|
|||
|
|||
getElementsByTagname
On Feb 17, 6:24*pm, senderj wrote:
I am writing a marco to put a html table into cells. I am able to * * Set doc_tables = ie.Document.getElementsByTagname("table") * * Set tab_rows = doc_tables(7).getElementsByTagname("tr") But I hit an error when trying to * * Set tab_cells = tab_rows.getElementsByTagname("td") Where can I read more about this kind of coding? Is this called ActiveX object DOM? You might also look at constructions such as: Set doc_tables = ie.document.getElementsByTagname("table") ActiveCell = doc_tables(7).innertext Activecell.Offset(1,0).Select ActiveCell = doc_tables(7).Rows(0).innertext Activecell.Offset(1,0).Select ActiveCell = doc_tables(7).Rows(0).Cells(2).innertext and see what they may have to offer...Ron |
#4
Posted to microsoft.public.excel.programming
|
|||
|
|||
getElementsByTagname
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? |
#5
Posted to microsoft.public.excel.programming
|
|||
|
|||
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? |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|