Web query error

Av8tordude

Well-known Member
Joined
Oct 13, 2007
Messages
1,074
Office Version
  1. 2019
Platform
  1. Windows
Sometimes I get an error when getting data from the web. (Either due to lost internet connection or slow internet connections.) The error occurs on Send. if, for example, the website can not be reached, lost internet, or slow internet, I would like to give a message to each scenario. How can I fix this?

Code:
    With Request
        .Open "GET", URL, False
        .setRequestHeader "Content-Type", "application/x-www-form-urlencoded; charset=UTF-8"
[B]        .send[/B]
        .waitForResponse
        Response = .responseText
    End With




Thank you kindly.
 

Excel Facts

Format cells as time
Select range and press Ctrl+Shift+2 to format cells as time. (Shift 2 is the @ sign).
Before your .send use On Error goto errorlabel. Place the label at the bottom like Reach:
and then do your error handling an create message boxes if needed.

https://docs.microsoft.com/en-us/office/vba/language/reference/user-interface-help/goto-statement

Something LIKE this
For website could not be reached and no internet you could send a request to a website like google.com and store the .status. If they are both “OK” (check what it should be In the locals window just in case) then the user has internet and the website could be reached.
 
Last edited:
Upvote 0
Thank you.. I used the error handling, but I'll look into the other part. Thanks. Cheers
 
Upvote 0
Thank you.. I used the error handling, but I'll look into the other part. Thanks. Cheers
This may help
Code:
Function URL_Exists(URL As String) As Boolean
    Dim Request As Object
    Dim ff As Integer
    Dim rc As Variant
    
    On Error GoTo EndNow
    Set Request = CreateObject("WinHttp.WinHttpRequest.5.1")
    With Request
      .Open "GET", URL, False
      .send
      rc = .StatusText
    End With
    Set Request = Nothing
    If rc = "OK" Then
        URL_Exists = True
'            Else
'                ISReal = False
    End If
    


EndNow:
End Function
 
Upvote 0

Forum statistics

Threads
1,213,567
Messages
6,114,344
Members
448,570
Latest member
rik81h

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