A family of Microsoft spreadsheet software with tools for analyzing, charting, and communicating data.
Here is a sample macro for checking the internet connection status in VBA:
Sub CheckInternetConnection()
Dim objHTTP As Object
Set objHTTP = CreateObject("WinHttp.WinHttpRequest.5.1")
On Error Resume Next
objHTTP.Open "GET", "https://www.google.com", False objHTTP.Send
If objHTTP.Status = 200 Then MsgBox "Internet connection is active.", vbInformation, "Connection Status" Else MsgBox "Internet connection is not active. Please check your connection.", vbCritical, "Connection Status" End If
End Sub
You can call this function from another procedure to check the internet connection status.
Here is an example:
Sub TestInternetConnection()
If CheckInternetConnection = False Then 'Internet connection is not active MsgBox "Internet connection is not active. Please check your connection.", vbCritical, "Connection Status" Else 'Internet connection is active MsgBox "Internet connection is active.", vbInformation, "Connection Status" End If
End Sub
In this example, the TestInternetConnection procedure calls the CheckInternetConnection function and displays a message to the user based on the result.