VBA EXTRACT TABLE HTML TO EXCEL

Excel Facts

Convert text numbers to real numbers
Select a column containing text numbers. Press Alt+D E F to quickly convert text to numbers. Faster than "Convert to Number"

roykana

Board Regular
Joined
Mar 8, 2018
Messages
120
Office Version
  1. 2010
Platform
  1. Windows
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
 

Watch MrExcel Video

Forum statistics

Threads
1,130,192
Messages
5,640,764
Members
417,165
Latest member
Hilders1

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
Top