check internet connection vba

Hi, sometimes we need to update the excel workbook to update on load or when someone press button to update. But if there is no internet connection it might throw error or exception.

To avoid exception and error we can check the internet connection using vba. Please find below code to determine internet connection available or not.

Please add reference of Microsoft XML, v3.0

Function checkInternetConnection() As Integer
On Error Resume Next
 checkInternetConnection = False
 Dim http As ServerXMLHTTP
 Dim varProjectID, varCatID, strT As String
 Set http = New ServerXMLHTTP
 http.Open "GET", ""
 http.SetRequestHeader "Accept", "application/xml"
 http.SetRequestHeader "Content-Type", "application/xml"
 http.Send strT
 If Err = 0 Then
 checkInternetConnection = True
 MsgBox "Internet connection established"
  MsgBox "Internet connection not established: " & Err.Description & "", 64, "No Internet Connection Found!"
 End If
End Function

if face any problem let me know.

Happy programming……….cheers!

Posted by | View Post | View Group