JudahRaion
New Member
- Joined
- Oct 13, 2011
- Messages
- 20
Hi everyone,
I need your help to figure how can I take from a piece of code an table to excel.
I find where table is and I create a variable to put the table in, but when I try to use that piece of code like html document, vba shows me this message: "Run-time error '424': Object required".
Thank you all
</table")>
I need your help to figure how can I take from a piece of code an table to excel.
I find where table is and I create a variable to put the table in, but when I try to use that piece of code like html document, vba shows me this message: "Run-time error '424': Object required".
Code:
Sub Tester()
Dim tbls, tbl, trs, tr, tds, td, r, c
Dim IE As New InternetExplorerMedium
IE.navigate "URL"
IE.Visible = False
Application.Wait Now + TimeSerial(0, 0, 4)
allHTML = IE.document.body.innerHTML
''Carteira
If InStr(allHTML, "Carteira de Títulos") > 0 Then
leng = Len("Carteira de Títulos")
carteira = Mid(allHTML, InStr(allHTML, "Carteira de Títulos") + leng, Len(allHTML))
leng = Len(" carteira = Mid(carteira, InStr(carteira, "<table") +="" leng,="" instr(carteira,="" "<="" table="">") + leng)
'Range("A3") = carteira
End If
'error shows here
Set tbls = carteira.getElementsByTagName("table")
For r = 0 To tbls.Length - 1
Debug.Print r, tbls(r).Rows.Length
Next r
Set tbl = carteira.getElementsByTagName("table")(0)
Set trs = tbl.getElementsByTagName("tr")
For r = 0 To trs.Length - 1
Set tds = trs(r).getElementsByTagName("td")
'if no then look for
If tds.Length = 0 Then Set tds = trs(r).getElementsByTagName("th")
For c = 0 To tds.Length - 1
ActiveSheet.Range("B4").Offset(r, c).Value = tds(c).innerText
Next c
Next r
End Sub
Thank you all
</table")>