Are there any VBA code to look for a present internet connection?
I have a code that will run on a timer. This code will open a file on a local network share drive.
I usually use the code below to determine if a network connection exits. The function returns true or false.
Declaration:
Private Declare Function InternetGetConnectedStateEx Lib "wininet.dll" (ByRef _
lpdwFlags As Long, ByVal ipszConnectionName As String, ByVal _
dwNameLen As Integer, ByVal dwReserved As Long) As Long
Function:
Public Function IsInternetConnected() As Boolean
Dim strConnType As String
Dim lngReturnStatus As Long
IsInternetConnected = False
lngReturnStatus = InternetGetConnectedStateEx(lngReturnStatus, strConnType, 254, 0)
If lngReturnStatus = 1 Then IsInternetConnected = True
End Function
Using the function in a Sub:
If IsInternetConnected = False Then
output = MsgBox("No Network Connection Detected!", vbExclamation, "No Connection")
Else
Do stuff that requires the network connection
End If