GetElementByClassName

Excel Facts

Enter current date or time
Ctrl+: enters current time. Ctrl+; enters current date. Use Ctrl+: Ctrl+; Enter for current date & time.
hi
try,,,
Code:
Option Explicit

'reference to Microsoft HTML Object Library
Sub Web_Table_Option_One()

    Dim objTable As Object
    Dim lRow As Long
    Dim lngTable As Long
    Dim lngRow As Long
    Dim lngCol As Long
    Dim ActRw As Long

    Dim HTMLdoc As New HTMLDocument

    With CreateObject("MSXML2.XMLHTTP.6.0")
        .Open "GET", "https://www.learnthat.org/pages/view/roots.html", False
        .send
        HTMLdoc.body.innerHTML = .responseText
    End With

    Set objTable = HTMLdoc.body.getElementsByTagName("Table")

    For lngTable = 0 To objTable.Length - 1
        For lngRow = 0 To objTable(lngTable).Rows.Length - 1
            For lngCol = 0 To objTable(lngTable).Rows(lngRow).Cells.Length - 1
                Cells(ActRw + lngRow + 1, lngCol + 1) = objTable(lngTable).Rows(lngRow).Cells(lngCol).innerText
            Next lngCol
        Next lngRow
        ActRw = ActRw + objTable(lngTable).Rows.Length + 1
    Next lngTable

End Sub
 
Upvote 0
Hello Pike,

I get a compile error:

User-defined type not defined

The error is pointing to the lines in red

Code:
[COLOR=#333333]Option Explicit[/COLOR]'reference to Microsoft HTML Object Library
[COLOR=#ff0000][B]Sub Web_Table_Option_One()[/B][/COLOR]

    Dim objTable As Object
    Dim lRow As Long
    Dim lngTable As Long
    Dim lngRow As Long
    Dim lngCol As Long
    Dim ActRw As Long

    Dim [B][COLOR=#ff0000]HTMLdoc As New HTMLDocument[/COLOR][/B]

    With CreateObject("MSXML2.XMLHTTP.6.0")
        .Open "GET", "https://www.learnthat.org/pages/view/roots.html", False
        .send
        HTMLdoc.body.innerHTML = .responseText
    End With

    Set objTable = HTMLdoc.body.getElementsByTagName("Table")

    For lngTable = 0 To objTable.Length - 1
        For lngRow = 0 To objTable(lngTable).Rows.Length - 1
            For lngCol = 0 To objTable(lngTable).Rows(lngRow).Cells.Length - 1
                Cells(ActRw + lngRow + 1, lngCol + 1) = objTable(lngTable).Rows(lngRow).Cells(lngCol).innerText
            Next lngCol
        Next lngRow
        ActRw = ActRw + objTable(lngTable).Rows.Length + 1
    Next lngTable
 [COLOR=#333333]End Sub[/COLOR]
 
Upvote 0

Forum statistics

Threads
1,214,797
Messages
6,121,629
Members
449,041
Latest member
Postman24

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top