reasem
New Member
- Joined
- Nov 15, 2019
- Messages
- 38
Hello all, I have this code I'm working on and it originally worked before I added code to attempt to get it to loop through multiple links to get the tables from those too. I tried to run it and it gives me no errors but It does not paste any tables to my sheet. The immediate window shows all the links in the range that I'm trying to pull tables from but my internet explorer doesn't actually navigate anywhere.
Is there anything I can do to edit the code to do what I'm looking for? Thanks!
Is there anything I can do to edit the code to do what I'm looking for? Thanks!
VBA Code:
Sub WebScrape()
Dim HTMLDoc As New HTMLDocument
Dim objTable As Object
Dim lRow As Long
Dim lngTable As Long
Dim lngRow As Long
Dim lngCol As Long
Dim ActRw As Long
Dim c As Range
Dim objIE As InternetExplorer
Set objIE = New InternetExplorer
For Each c In Sheets("Links").Range("C6:C27")
objIE.navigate c.Value
Do Until objIE.readyState = 4 And Not objIE.Busy
DoEvents
Loop
Application.Wait (Now + TimeValue("0:00:03"))
HTMLDoc.body.innerHTML = objIE.document.body.innerHTML
With HTMLDoc.body
Set objTable = .getElementsByTagName("table")
For lngTable = 0 To objTable.Length - 1
For lngRow = 0 To objTable(lngTable).Rows.Length - 1
For lngCol = 0 To objTable(lngTable).Rows(lngRow).Cells.Length - 1
ThisWorkbook.Sheets("Sheet1").Cells(ActRw + lngRow + 1, lngCol + 1) = objTable(lngTable).Rows(lngRow).Cells(lngCol).innerText
Next lngCol
Next lngRow
ActRw = ActRw + objTable(lngTable).Rows.Length + 1
Next lngTable
End With
Debug.Print c
Next c
objIE.Quit
End Sub