Import Website Table to excel

samzie83

New Member
Joined
Jun 7, 2016
Messages
9
Hi, I am attempting to import the below website table into excel with great difficulty.

https://www.flashscore.com/nhl/standings/

I believe the Standing table which I am trying to import is a JavaScript table.

What is the easiest way (beside manually copying and pasting every time) to get these details onto excel?

Regards,

Sam
 

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.
The following code will first create a new worksheet within the workbook running the code, and then copy the table into the newly created worksheet. The code should be placed in a regular module. Note that you'll need to set a reference to Microsoft Internet Controls, and Microsoft HTML Object Library, under VBE > Tools > References.

Code:
Option Explicit

Sub test()


    'Set a reference (VBE > Tools > References) to the following libraries:
    '   1) Microsoft Internet Controls
    '   2) Microsoft HTML Object Library
    
    Dim IE As New SHDocVw.InternetExplorer
    Dim HTMLDoc As New MSHTML.HTMLDocument
    Dim HTMLTable As MSHTML.HTMLTable
    Dim HTMLRow As MSHTML.HTMLTableRow
    Dim wksDest As Worksheet
    Dim i As Long
    Dim j As Long
    
    With IE
        .Visible = False
        .navigate "https://www.flashscore.com/nhl/standings/"
        Do While .Busy Or .readyState <> READYSTATE_COMPLETE
            DoEvents
        Loop
    End With
    
    Set HTMLDoc = IE.document
    
    Set HTMLTable = HTMLDoc.getElementById("table-type-1")
    
    If Not HTMLTable Is Nothing Then
        Set wksDest = ThisWorkbook.Worksheets.Add
        For i = 0 To HTMLTable.Rows.Length - 1
            For j = 0 To HTMLTable.Rows(i).Cells.Length - 1
                wksDest.Cells(i + 1, j + 1).Value = HTMLTable.Rows(i).Cells(j).innerText
            Next j
        Next i
    Else
        MsgBox "Table not found!", vbExclamation
    End If
    
    Set IE = Nothing
    Set HTMLDoc = Nothing
    Set HTMLTable = Nothing
    Set HTMLRow = Nothing
    Set wksDest = Nothing
    
End Sub

Hope this helps!
 
Upvote 0
Thanks for the quick response Domenic. Are you able to give an example of setting a reference for Microsoft Internet Controls and HTML Object Libary. I am a little unsure how this works.
 
Upvote 0
Okay, let's take it step by step...

1) Open the Visual Basic Editor by pressing and holding down the ALT button, and then pressing the F11 button.

2) Under the menu in the Visual Basic Editor, first select Tools, and then select References.

3) Under Available References, scroll down until you see Microsoft Internet Controls, and then check/select it.

4) Again, under Available References, scroll down until you see Microsoft HTML Object Library, and then check/select it.

5) Click on OK, and then save your workbook.

Then you'll be able to run the code by going to the View tab in Excel and selecting Macros or by using the keyboard shortcut ALT + F8, and then selecting the sub, and then clicking on Run. By the way, in the code itself, you can change the name of the sub from 'test' to something more meaningful. For example, if you want the sub to be called DownloadStanding, you can replace...

Code:
Sub test()

with

Code:
Sub DownloadStanding()

Hope this helps!
 
Last edited:
Upvote 0

Forum statistics

Threads
1,223,894
Messages
6,175,250
Members
452,623
Latest member
Techenthusiast

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