Nelson78
Well-known Member
- Joined
- Sep 11, 2017
- Messages
- 526
- Office Version
- 2007
Hello everybody.
I've been grasping a lot of data from a website via Excel using the following code.
The operation is usually repeated hundreds of times with no problems.
But sometimes it bumps into an error
Run-Time Error 91 Object Variable or With Block Variable Not Set
usually on row
with a complete stop of the task.
Now, with the high volume of data I deal with it is a loss of time to restart the process, and it is not a problem if only one page is not grasped.
How could I instruct the macro to ignore the error and keep on?
Thank's.
I've been grasping a lot of data from a website via Excel using the following code.
Code:
Dim tbls, tbl, trs, tr, tds, td, R, c
Set tbls = IE.document.getElementsByTagName("table")
For R = 0 To tbls.Length - 1
Debug.Print R, tbls(R).Rows.Length
Next R
Set tbl = IE.document.getElementsByTagName("table")(47)
Set trs = tbl.getElementsByTagName("tr")
For R = 0 To trs.Length - 1
Set tds = trs(R).getElementsByTagName("td")
If tds.Length = 0 Then Set tds = trs(R).getElementsByTagName("th")
For c = 0 To tds.Length - 1
ThisWorkbook.Worksheets("Sheet1").Range("A1").Offset(R, c).Value = CleanAll(tds(c).innerText)
Next c
Next R
The operation is usually repeated hundreds of times with no problems.
But sometimes it bumps into an error
Run-Time Error 91 Object Variable or With Block Variable Not Set
usually on row
Code:
ThisWorkbook.Worksheets("Sheet1").Range("A1").Offset(R, c).Value = CleanAll(tds(c).innerText)
Now, with the high volume of data I deal with it is a loss of time to restart the process, and it is not a problem if only one page is not grasped.
How could I instruct the macro to ignore the error and keep on?
Thank's.