Oliver Dewar
Board Regular
- Joined
- Apr 17, 2011
- Messages
- 201
Hi Guys.
I'm doing some web automation using the script below:
Sometimes I encounter urls which hang for minutes before resolving, or they don't resolve at all.
How can I set a timeout on this method?
I've tried this but it doesn't seem to be working:
Any ideas?
Thanks
I'm doing some web automation using the script below:
Code:
strURL = Activecell.value 'this is the url to test
Set objhttp = CreateObject("MSXML2.XMLHTTP")
objhttp.Open "HEAD", strUrl, False
objhttp.send
If objhttp.statusText <> "OK" Then
Activecell.Interior.Color = 255
End If
Sometimes I encounter urls which hang for minutes before resolving, or they don't resolve at all.
How can I set a timeout on this method?
I've tried this but it doesn't seem to be working:
Code:
Dim TimeOut As Double, iTimeTaken As Integer
Set objHttp = CreateObject("MSXML2.XMLHTTP")
objHttp.Open "HEAD", strUrl, False
objHttp.send
iTimeTaken = 0
'loop until the page has loaded or timed out
Do Until iTimeTaken > TimeOut
Application.Wait TimeSerial(Hour(Now()), Minute(Now()), Second(Now()) + 1)
iTimeTaken = iTimeTaken + 1
If objHttp.readyState = 4 Then
'page has loaded
Exit Do
End If
Loop
If objHttp.readyState <> 4 Then
'if the readystate is still 4 then it timed out
MsgBox "Timed Out"
Exit Sub
End If
Any ideas?
Thanks
