Ingrese este código en un módulo
#If VBA7 And Win64 Then
' 64-bits
Private Declare PtrSafe Function InternetCheckConnection Lib "wininet.dll" Alias "InternetCheckConnectionA" (ByVal lpszUrl As String, ByVal dwFlags As Long, ByVal dwReserved As Long) As Long
#Else
' 32-bits
Private Declare Function InternetCheckConnection Lib "wininet.dll" Alias "InternetCheckConnectionA" (ByVal lpszUrl As String, ByVal dwFlags As Long, ByVal dwReserved As Long) As Long
#End If
Public Function funConexionInternet() As Boolean
On Error GoTo Err_Local
Const cUrl = "https://www.google.com/"
funConexionInternet = InternetCheckConnection(cUrl, &H1, 0&)
If funConexionInternet = False Then
MsgBox "No está conectado a internet", vbCritical, "Error internet"
Application.Quit
Else
funConexionInternet = True
End If
Exit_Local:
On Error GoTo 0
Exit Function
Err_Local:
MsgBox Err.Description, vbCritical, Err.Number
Resume Exit_Local
End Function
Llame la función funConexionInternet() si retorna True es porque tiene internet. Este código lo utilizo en VBA, es posible que deba modificar la llamada a la API InternetCheckConnection