Vérifier si la connexion à Internet est établie.

YANN-56

XLDnaute Barbatruc
Bonsoir à ceux qui passeront par là.

Avant de lancer d'autres procédures, j'ai besoin de savoir
si mon ordinateur est bien connecté à Internet.

Est-ce possible?

Si oui; Merci de m'aiguiller.

Bonne soirée à tous

Yann
 
G

Guest

Guest
Re : Vérifier si la connexion à Internet est établie.

Bonjour Yann,
Dans un module général
Code:
'Example by Vijay Phulwadhawa (vijaycg44@hotmail.com)
Public Declare Function InternetGetConnectedState Lib "wininet.dll" (ByRef lpdwFlags As Long, ByVal dwReserved As Long) As Long
Public Function IsConnected() As Boolean
    If InternetGetConnectedState(0&, 0&) = 1 Then
        IsConnected = True
    Else
        IsConnected = False
    End If
End Function

A+
 

YANN-56

XLDnaute Barbatruc
Re : Vérifier si la connexion à Internet est établie.

Bonjour Hasco qui m'a déjà tant aidé, et à ceux qui passeront par là.

Ton code, testé, me donne l'information sur le branchement
ou pas de l'ordinateur à un moyen de connexion internet. Utile aussi.
Mais j'ai certainement mal formulé ma question! :(

En réalité j'aurais dû parler de "Connexion Active"

En fouillant et bidouillant,
j'en ai tiré un truc qui fonctionne parfaitement chez moi

Code:
 '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

Je joins le Classeur; au cas où il puisse servir à quelqu'un.

Merci à toi, et bonne fin de journée à tous.

Yann
 

Pièces jointes

  • EN_LIGNE.xls
    32 KB · Affichages: 79

Discussions similaires

Statistiques des forums

Discussions
312 502
Messages
2 089 042
Membres
104 010
dernier inscrit
Freba