I'm trying to get the content of a table on an internal web page down into an excel sheet, but I can't grab any of the HTML elements. I have tried grabbing all the elements by ID, Classname and tagname but to no avail. Can someone give me a clue on what I'm doing wrong?
Sub Shuffle()
Application.DisplayAlerts = False
'On Error GoTo ErrHandler
Dim SheetName, FavNumber As String
'LTI
SheetName = "LTI"
FavNumber = "2282804"
'Call IE_Sledgehammer
Dim ie As InternetExplorerMedium, I As Long, strText As String
Dim doc As Object, hTable As Object, hBody As Object, hTR As Object, hTD As Object
Dim tb As Object, bb As Object, tr As Object
Dim y As Long, z As Long, wb As Excel.Workbook, ws As Excel.Worksheet
Set wb = Excel.ActiveWorkbook
'Set ws = wb.ActiveSheet
'LastRow = Sheets(SheetName).Cells(Sheets(SheetName).Rows.Count, "A").End(xlUp).Row
'If LastRow > 1 Then
' Sheets(SheetName).Range("A2:AA" & LastRow + 1).ClearContents
'End If
'Application.Wait (Now + TimeValue("0:00:02"))
Set ie = Nothing
Application.Wait (Now + TimeValue("0:00:02"))
Set ie = New InternetExplorerMedium
ie.Visible = True
ie.navigate "https://synergi.de-prod.dk/synergi/favourite/" & FavNumber
On Error Resume Next
Do While ie.Busy: DoEvents: Loop
Do While ie.readyState <> 4:
Set doc = ie.document
Dim td As Object
Set td = doc.getElementsByTagName("td")
Set Post6a = doc.getElementsByTagName("th")(0).outerText: MsgBox Post6a
Set Post6b = doc.getElementsByTagName("th")(0).innerText: MsgBox Post6b
Set Post6c = doc.getElementsByTagName("td"): MsgBox Post6c.Length
Dim th As Object
Set th = doc.getElementsByTagName("th")
Set Post8a = doc.getElementsByTagName("td")(0).outerText: MsgBox Post8a
Set Post8b = doc.getElementsByTagName("td")(0).innerText: MsgBox Post8b
Set Post8c = doc.getElementsByTagName("th"): MsgBox Post8c.Length
Dim span As Object
Set span = doc.getElementsByTagName("span")
Set Post7a = doc.getElementsByTagName("span")(0).outerText: MsgBox Post7a
Set Post7b = doc.getElementsByTagName("span")(0).innerText: MsgBox Post7b
Set Post7c = doc.getElementsByTagName("span"): MsgBox Post7c.Length
Dim div As Object
Set span = doc.getElementsByTagName("div")
Set Post9a = doc.getElementsByTagName("div")(0).outerText: MsgBox Post9a
Set Post9b = doc.getElementsByTagName("div")(0).innerText: MsgBox Post9b
Set Post9c = doc.getElementsByTagName("div"): MsgBox Post9c.Length
y = 1 'Column A in Excel
z = 2 'Row 1 in Excel
Set hTable = doc.getElementsByTagName("table")
For Each tb In hTable
Set hBody = tb.getElementsByTagName("tbody")
For Each bb In hBody
Set hTR = bb.getElementsByTagName("tr")
For Each tr In hTR
Set hTD = tr.getElementsByTagName("td")
y = 1 ' Resets back to column A
For Each td In hTD
wb.Sheets(SheetName).Cells(z, y).Value = td.innerText
y = y + 1
'MsgBox td.innerText
Next td
DoEvents
z = z + 1
Next tr
Exit For
Next bb
Exit For
Next tb
Application.Wait (Now + TimeValue("0:00:02"))
'IE.Quit
ie.Quit
End Sub
