title: Excel VBA - Check if connected to internet AND if its via Wifi or Ethernet
body: <p>I need to alert users before running a macro which takes a lot longer if run on Wifi as opposed to the company LAN.</p>
  
  <hr>
  
  <p>I have found the following code:</p>
  
  <p><a href="http://vbadud.blogspot.com/2010/05/how-to-check-internet-connectivity.html#P8djz6QY785Mde3B.99" rel="nofollow noreferrer">Checking for internet connection using VBA</a></p>
  
  <p>The following code snippet uses API functions to check Internet connectivity and also the type of connection
  :</p>
  
  <pre><code>Public Declare Function InternetGetConnectedState _
                           Lib "wininet.dll" (lpdwFlags As Long, _
                                              ByVal dwReserved As Long) As Boolean
  
  Private Declare Function InternetGetConnectedStateEx Lib "wininet.dll" Alias "InternetGetConnectedStateExA" ( _
  ByRef lpdwFlags As Long, _
  ByVal lpszConnectionName As String, _
  ByVal dwNameLen As Long, _
  ByVal dwReserved As Long) As Long
  
  
  'Local system uses a modem to connect to the Internet.
  Private Const INTERNET_CONNECTION_MODEM As Long = &amp;H1
  
  'Local system uses a LAN to connect to the Internet.
  Private Const INTERNET_CONNECTION_LAN As Long = &amp;H2
  
  'Local system uses a proxy server to connect to the Internet.
  Private Const INTERNET_CONNECTION_PROXY As Long = &amp;H4
  
  The following API functions are used
  
  Function IsConnected() As Boolean
  
      Dim Stat As Long
  
      IsConnected = (InternetGetConnectedState(Stat, 0&amp;) &lt;&gt; 0)
  
      If IsConnected And INTERNET_CONNECTION_LAN Then
          MsgBox "Lan Connection"
      ElseIf IsConnected And INTERNET_CONNECTION_MODEM Then
          MsgBox "Modem Connection"
      ElseIf IsConnected And INTERNET_CONNECTION_PROXY Then
          MsgBox "Proxy"
      End If
  End Function
  </code></pre>
  
  <p>If you want to know just if it is connected or not you can use the following:</p>
  
  <pre><code>CBool(InternetGetConnectedStateEx(0, vbNullString, 512, 0&amp;))
  </code></pre>
  
  <hr>
  
  <p>This tells me I have a LAN connection, but it does so whether I am on WIFI or connected to the LAN. I need to distinguish between them.</p>
  
  <p>Does anyone know how I can do this please?</p>
  
  <p>Cheers</p>