I have tried the following code to scrape a table from local HTML file stored on my PC
Sub Test()
Dim mtbl As Object
Dim tableData As Object
Dim tRow As Object
Dim tcell As Object
Dim trowNum As Integer
Dim tcellNum As Integer
Dim webpage As New HTMLDocument
Dim fPath As String
Dim strCnt As String
Dim f As Integer
fPath = Environ("USERPROFILE") & "\Desktop\LocalHTML.txt"
f = FreeFile()
Open fPath For Input As #f
strCnt = Input(LOF(f), f)
Close #f
webpage.body.innerHTML = strCnt
Set mtbl = webpage.getElementsByTagName("Table")(0)
Set tableData = mtbl.getElementsByTagName("tr")
Debug.Print tableData.Item(0).innerText
On Error GoTo TryAgain:
trowNum = 1
For Each tRow In tableData
For Each tcell In tRow.Children
tcellNum = tcellNum + 1
Sheet1.Cells(trowNum, tcellNum) = tcell.innerText
Next tcell
trowNum = trowNum + 1
tcellNum = 0
Next tRow
Exit Sub
TryAgain:
Application.Wait Now + TimeValue("00:00:02")
Err.Clear
Resume
End Sub
The code works with no errors but the results are incorrect in two points First the characters in Arabic appears on worksheet as questions marks. I mean the unicode characters are not read correctly Second point the data is scattered on the sheet in an unorganized structure
Here's the link of the local HTML file http://www.mediafire.com/file/oxpyzv4gc53kuwg/LocalHTML.txt
Thanks advanced for help