VBA EXTRACT TABLE HTML TO EXCEL

Excel Facts

Which lookup functions find a value equal or greater than the lookup value?
MATCH uses -1 to find larger value (lookup table must be sorted ZA). XLOOKUP uses 1 to find values greater and does not need to be sorted.
Dear All Master,
I want to extract table data in html file in excel with vba code. I give the html file and excel output the link.
Link file : VBA EXTRACT TABLE HTML TO EXCEL - Google Drive
file


Please give me a solution.
Thanks

Roykana
Dear All Master,

I made a sample sample vba code but it didn't work. Maybe anyone can help me.

Thanks
roykana
VBA Code:
Option Explicit

Sub extractTablehtml()
    Dim IE As Object
    Dim theTable As Object
    Dim form As Variant, button As Variant
    Dim doc As Object

    Dim t As Variant
    Dim j As Integer
    Dim k As Integer

    Set IE = CreateObject("InternetExplorer.Application")
    ' navigate to a web page
    With IE
        .Visible = True
        .navigate ("https://datatables.net/")
    End With
    While IE.ReadyState <> 4
        DoEvents
    Wend

    Set doc = IE.document

    Set theTable = doc.getElementById("mytable").getElementsByTagName("tr")
    ' extract the data from tag and assign it to the first cell in the sheet
    Dim myValue As String

    j = 1
    k = 1

    For Each t In theTable
        myValue = t.innertext
        Cells(k, j).Value = myValue
        j = j + 1
        If j Mod 6 = 0 Then
            j = 1
            k = k + 1
        End If

    Next t

End Sub
 
Upvote 0

Forum statistics

Threads
1,224,820
Messages
6,181,155
Members
453,021
Latest member
Justyna P

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