Set timeout when automating Internet Explorer

Oliver Dewar

Board Regular
Joined
Apr 17, 2011
Messages
201
Hi All.

I'm using the following code to navigate Internet Explorer around:

Code:
With IE        

            .Visible = False
        
            .Navigate "http://www.domain.com/" 'this is could be any domain
            
            Do Until .readyState = 4: DoEvents: Loop

End With

Sometimes I hit a site which takes a long time to load, or has an on page coding error which causes it to never load.

I'd therefore like to set a timeout duration, so allow the browser say, 30 seconds, to load before aborting the load.

I guess the command would be put in the 'Do Until .readyState = 4' line as an OR statement... but how would I implement this? Any ideas or known solutions?

Cheers,

Oliver
 

Excel Facts

Save Often
If you start asking yourself if now is a good time to save your Excel workbook, the answer is Yes
Try this:
Rich (BB code):
  With IE
    .Visible = False
    .Navigate "http://www.domain.com/"         ' this is could be any domain
    Dim dt As Date
    dt = Now + TimeSerial(0, 0, 30)            ' 30 is timeout in seconds
    Do Until .readyState = 4
      DoEvents
      If Now > dt Then
        MsgBox "Timeout has happened", vbExclamation, "Canceled"
        Exit Sub
      End If
    Loop
  End With
 
Last edited:
Upvote 0

Forum statistics

Threads
1,216,188
Messages
6,129,401
Members
449,508
Latest member
futureskillsacademy

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top