Import Table from Web Page to Excel

Asked

Viewed 718 times

1

I want to take all the data from an internet table and put it in excel. I tried with the code below, but the following error appears in the line of 'For Each':

"Runtime error '438': Object does not accept this property or method"

Sub CCEE_precoMedio()

Dim ie As Object
Dim doc As Object, elem As Object, trow As Object

Set ie = CreateObject("InternetExplorer.Application")

ie.Navigate "https://www.ccee.org.br/portal/faces/pages_publico/o-que-fazemos/como_ccee_atua/precos/precos_medios?_adf.ctrl-state=trut1o6ix_5&_afrLoop="
ie.Visible = True

    Do Until (ie.readyState = 4 And Not ie.Busy)
        DoEvents
    Loop

Set doc = ie.document.getElementsByClassName("displaytag-Table_soma")

   r = 1
    For Each elem In doc.getElementsByTagName("tr")
        For Each trow In elem.getElementsByTagName("td")
            y = y + 1: Cells(r + 1, y + 1) = trow.innerText
        Next trow
        y = 0
        r = r + 1

    Next elem

End Sub

I believe the error lies in how I refer the item. How do I correct this?

  • 1

    The table is inside an iframe, so iframe must be accessed first. <iframe id="pt1:myFrame" class="xhg xwr p_AFFlow" frameborder="0" src="/preco/precoMedio.do" onload="AdfDhtmlInlineFramePeer.__iframeLoadHandler(event)" _adfloaded="1" height="4633" style="min-width: 0px; min-height: 0px; visibility: visible; height: 4618px;"></iframe>

  • It worked out Daniel! Thanks

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.