'Cela permet de vérifier si la connexion à Internet est établie,
'et de poursuivre ou non une procédure. (Ex: Envoi d'un Mail via VBA)
'Façon d'éviter attentes inutiles et éventuels plantages ...
Private Declare Function InternetGetConnectedState Lib "wininet" _
(ByRef dwflags As Long, _
ByVal dwReserved As Long) As Long
Private Const CONNEXION_ETABLIE As Long = &H40
Private Sub CommandButton1_Click()
x = GetNetConnectString()
End Sub
Private Function IsNetConnectOnline() As Boolean
IsNetConnectOnline = InternetGetConnectedState(0&, 0&)
End Function
Private Function GetNetConnectString() As String
Dim CONNEXION As Boolean
Dim dwflags As Long
If InternetGetConnectedState(dwflags, 0&) Then
If dwflags And CONNEXION_ETABLIE Then
CONNEXION = True
Else
CONNEXION = False
End If
End If
If CONNEXION = True Then
UserForm1.Label1.Caption = " Vous êtes bien connecté à Internet"
Else
UserForm1.Label1.Caption = " Vous n'êtes pas connecté à Internet"
End If
End Function