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://www.google.com" http.SetRequestHeader "Accept", "application/xml" http.SetRequestHeader "Content-Type", "application/xml" http.Send strT If Err = 0 Then checkInternetConnection = True MsgBox "Internet connection established" Else 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!
Thanks so much. I really do appreciate it.
I tried the wininet.dll approach but it doesn’t work like yours did. And it also stops me with ptrsafe on win64bit.
Just one question though. Does the user need to have MS XML 3.0 checked in their MS Excel VBA References? If so, how can I do it for him through VBA, if I can?
Hey nice to hear it’s worked for you.
Yes You need to add MX XML 3.0. You can google how to add reference in vba excel.:)
Thanks a lot dear.