user2063626
user2063626

Reputation:

Get All td from tr using VBA code

enter image description here enter image description here

I have a tr which is a object and has td. I want to get all td in another object variable tblTD. For that i used Set tblTD = tr.getelementsbytagname("td"). But when i check the lenght of tblTD it shows as 0. Can someone suggest how this can be done. Kindly refer the images attached. Thanks!

Upvotes: 3

Views: 10372

Answers (1)

Kevin Pope
Kevin Pope

Reputation: 2982

If you've set tr with the getElementsByTagName function, then you'll need to iterate through each tr object to get the child td objects (or you can just reference a single one):

Dim td As MSHTML.IHTMLElementCollection
Dim tr As MSHTML.IHTMLElementCollection
Dim trObj as MSHTML.HTMLGenericElement
Dim tdObj as MSHTML.HTMLGenericElement

Set tr = HTMLDoc.getElementsByTagName("tr")
For Each trObj In tr
    Set td = trObj.getElementsByTagName("td")
    For Each tdObj in td
        'do something with each td object'
    Next
Next

Upvotes: 4

Related Questions