Boostez vos compétences Excel avec notre communauté !

Rejoignez Excel Downloads, le rendez-vous des passionnés où l'entraide fait la force. Apprenez, échangez, progressez – et tout ça gratuitement ! 👉 Inscrivez-vous maintenant !

bernardrustrel

XLDnaute Occasionnel
Bonjour a tous
désireux avertir l'utilisateur de mon appli de sa connexion au réseau ou non, je cherche, en vain, une solution afin d'arriver à mes fins.
une âme charitable peut elle me venir en aide, merci par avance
 
Re : Conexion reseau

Bonsoir
en fait je voudrais être sur d'être connecte au réseau avant d'envoyer mon message via EXCEL. Je pense qu'il doit me falloir lire la base de registre pour en extraire l'info qui va bien mais je ne sais coment m(y prendre....

merci à vous
 
Re : Conexion reseau

bonsoir Bernard,

voici un code à mettre dans un UserForm Avec Deux commandButtons
1 nommé cmdInternet et l' autre cmdLocale
Ce code fait appel aux APIS Windows

Je pense que tu pourra l'adapter à ton besoin.

Code:
Option Explicit
Private Const INTERNET_CONNECTION_CONFIGURED = &H40
Private Const INTERNET_CONNECTION_LAN = &H2
Private Const INTERNET_CONNECTION_MODEM = &H1
Private Const INTERNET_CONNECTION_OFFLINE = &H20
Private Const INTERNET_CONNECTION_PROXY = &H4
Private Const INTERNET_RAS_INSTALLED = &H10
Private Declare Function InternetGetConnectedState Lib "wininet.dll" (ByRef lpdwFlags As Long, ByVal dwReserved As Long) As Long
Private Declare Function InternetGetConnectedStateEx Lib "wininet.dll" (ByRef lpdwFlags As Long, ByVal lpszConnectionName As String, ByVal dwNameLen As Integer, ByVal dwReserved As Long) As Long
Private Function GetLocalConnection()
    'KPD-Team 2001
    'URL: http://www.allapi.net/
    'E-Mail: KPDTeam@Allapi.net
    Dim Ret As Long
    
    'retrieve the connection status
    InternetGetConnectedState Ret, 0&
    'show the result
    If (Ret And INTERNET_CONNECTION_CONFIGURED) = INTERNET_CONNECTION_CONFIGURED Then GetLocalConnection = "Local system has a valid connection to the Internet, but it may or may not be currently connected."
    If (Ret And INTERNET_CONNECTION_LAN) = INTERNET_CONNECTION_LAN Then GetLocalConnection = "Local system uses a local area network to connect to the Internet."
    If (Ret And INTERNET_CONNECTION_MODEM) = INTERNET_CONNECTION_MODEM Then GetLocalConnection = "Local system uses a modem to connect to the Internet."
    If (Ret And INTERNET_CONNECTION_OFFLINE) = INTERNET_CONNECTION_OFFLINE Then GetLocalConnection = "Local system is in offline mode."
    If (Ret And INTERNET_CONNECTION_PROXY) = INTERNET_CONNECTION_PROXY Then GetLocalConnection = "Local system uses a proxy server to connect to the Internet."
    If (Ret And INTERNET_RAS_INSTALLED) = INTERNET_RAS_INSTALLED Then GetLocalConnection = "Local system has RAS installed."
    
End Function
Private Sub GetInternetConnection()
    Dim sConnType As String * 255
    Dim Ret As Long
    Ret = InternetGetConnectedStateEx(Ret, sConnType, 254, 0)
    If Ret = 1 Then
        MsgBox "You are connected to Internet via a " & sConnType, vbInformation
    Else
        MsgBox "You are not connected to internet", vbInformation
    End If
End Sub
 
Private Sub cmdInternet_Click()
GetInternetConnection
End Sub
Private Sub cmdLocale_Click()
MsgBox GetLocalConnection
End Sub
Private Sub UserForm_Click()
End Sub

A bientôt
 
- Navigue sans publicité
- Accède à Cléa, notre assistante IA experte Excel... et pas que...
- Profite de fonctionnalités exclusives
Ton soutien permet à Excel Downloads de rester 100% gratuit et de continuer à rassembler les passionnés d'Excel.
Je deviens Supporter XLD

Discussions similaires

Réponses
7
Affichages
515
Retour