Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 298
Default 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   Report Post  
Posted to microsoft.public.excel.programming
ron ron is offline
external usenet poster
 
Posts: 118
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 298
Default 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
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT +1. The time now is 07:05 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"