[COLOR=darkblue]Option[/COLOR] [COLOR=darkblue]Explicit[/COLOR]
[COLOR=darkblue]Sub[/COLOR] GetLeaderboard()
[COLOR=green]'Set a reference (VBE > Tools > References) to the following libraries:[/COLOR]
[COLOR=green]' 1) Microsoft Internet Controls[/COLOR]
[COLOR=green]' 2) Microsoft HTML Object Library[/COLOR]
[COLOR=darkblue]Dim[/COLOR] IE [COLOR=darkblue]As[/COLOR] [COLOR=darkblue]New[/COLOR] SHDocVw.InternetExplorer
[COLOR=darkblue]Dim[/COLOR] HTMLDoc [COLOR=darkblue]As[/COLOR] [COLOR=darkblue]New[/COLOR] MSHTML.HTMLDocument
[COLOR=darkblue]Dim[/COLOR] HTMLTable [COLOR=darkblue]As[/COLOR] MSHTML.IHTMLTable
[COLOR=darkblue]Dim[/COLOR] HTMLRow [COLOR=darkblue]As[/COLOR] MSHTML.IHTMLElement
[COLOR=darkblue]Dim[/COLOR] arrLeaderboard() [COLOR=darkblue]As[/COLOR] [COLOR=darkblue]Variant[/COLOR]
[COLOR=darkblue]Dim[/COLOR] EndTime [COLOR=darkblue]As[/COLOR] [COLOR=darkblue]Single[/COLOR]
[COLOR=darkblue]Dim[/COLOR] r [COLOR=darkblue]As[/COLOR] [COLOR=darkblue]Long[/COLOR]
[COLOR=darkblue]Dim[/COLOR] c [COLOR=darkblue]As[/COLOR] [COLOR=darkblue]Long[/COLOR]
[COLOR=darkblue]With[/COLOR] IE
.Visible = [COLOR=darkblue]False[/COLOR]
.navigate "https://www.foxsports.com/golf/leaderboard"
[COLOR=darkblue]Do[/COLOR] [COLOR=darkblue]While[/COLOR] .Busy [COLOR=darkblue]Or[/COLOR] .readyState <> READYSTATE_COMPLETE
DoEvents
[COLOR=darkblue]Loop[/COLOR]
[COLOR=darkblue]End[/COLOR] [COLOR=darkblue]With[/COLOR]
[COLOR=green]'Pause for 5 seconds to ensure data has fully loaded[/COLOR]
EndTime = Timer + 5
[COLOR=darkblue]Do[/COLOR] [COLOR=darkblue]While[/COLOR] Timer < EndTime
DoEvents
[COLOR=darkblue]Loop[/COLOR]
[COLOR=darkblue]Set[/COLOR] HTMLDoc = IE.document
[COLOR=darkblue]Set[/COLOR] HTMLTable = HTMLDoc.getElementsByClassName("wisfb_standard wisfb_standings wisfb_hoverHighlight wisfb_golfLeaderTable")(0)
[COLOR=darkblue]If[/COLOR] [COLOR=darkblue]Not[/COLOR] HTMLTable [COLOR=darkblue]Is[/COLOR] [COLOR=darkblue]Nothing[/COLOR] [COLOR=darkblue]Then[/COLOR]
[COLOR=green]'Allocate storage space for arrLeaderboard to hold data from the leaderboard table[/COLOR]
[COLOR=darkblue]ReDim[/COLOR] arrLeaderboard(0 [COLOR=darkblue]To[/COLOR] HTMLTable.Rows.Length - 1, 0 [COLOR=darkblue]To[/COLOR] HTMLTable.Rows(0).Cells.Length - 1)
[COLOR=green]'Fill arrLeaderboard with data from the leaderboard table[/COLOR]
r = 0
[COLOR=darkblue]For[/COLOR] [COLOR=darkblue]Each[/COLOR] HTMLRow [COLOR=darkblue]In[/COLOR] HTMLTable.Rows
[COLOR=darkblue]If[/COLOR] HTMLRow.Cells.Length > 1 [COLOR=darkblue]Then[/COLOR]
[COLOR=darkblue]For[/COLOR] c = 0 [COLOR=darkblue]To[/COLOR] HTMLRow.Cells.Length - 2
arrLeaderboard(r, c) = HTMLRow.Cells(c).innerText
[COLOR=darkblue]Next[/COLOR] c
r = r + 1
[COLOR=darkblue]End[/COLOR] [COLOR=darkblue]If[/COLOR]
[COLOR=darkblue]Next[/COLOR] HTMLRow
[COLOR=green]'Delete the Leaderboard worksheet, if it already exists[/COLOR]
[COLOR=darkblue]On[/COLOR] [COLOR=darkblue]Error[/COLOR] [COLOR=darkblue]Resume[/COLOR] [COLOR=darkblue]Next[/COLOR]
Application.DisplayAlerts = [COLOR=darkblue]False[/COLOR]
ThisWorkbook.Worksheets("Leaderboard").Delete
Application.DisplayAlerts = [COLOR=darkblue]True[/COLOR]
[COLOR=darkblue]On[/COLOR] [COLOR=darkblue]Error[/COLOR] [COLOR=darkblue]GoTo[/COLOR] 0
[COLOR=green]'Create a new worksheet and name it Leaderboard[/COLOR]
ThisWorkbook.Worksheets.Add(Before:=ThisWorkbook.Worksheets(1)).Name = "Leaderboard"
[COLOR=green]'Transfer the contents of arrLeaderboard to the Leaderboard worksheet[/COLOR]
Range("A1").Resize(UBound(arrLeaderboard, 1), UBound(arrLeaderboard, 2)).Value = arrLeaderboard
[COLOR=green]'Format the Leaderboard worksheet[/COLOR]
Cells.WrapText = [COLOR=darkblue]False[/COLOR]
Columns.AutoFit
[COLOR=darkblue]Else[/COLOR]
MsgBox "Leaderboard table not found!", vbExclamation
[COLOR=darkblue]End[/COLOR] [COLOR=darkblue]If[/COLOR]
IE.Quit
[COLOR=darkblue]Set[/COLOR] IE = [COLOR=darkblue]Nothing[/COLOR]
[COLOR=darkblue]Set[/COLOR] HTMLDoc = [COLOR=darkblue]Nothing[/COLOR]
[COLOR=darkblue]Set[/COLOR] HTMLTable = [COLOR=darkblue]Nothing[/COLOR]
[COLOR=darkblue]Set[/COLOR] HTMLRow = [COLOR=darkblue]Nothing[/COLOR]
[COLOR=darkblue]End[/COLOR] [COLOR=darkblue]Sub[/COLOR]