title: Determine if connected to VPN or Office Intranet or Office Wifi using excel vba
body: <p>I have the following code with which i am successfully checking if i am connected to VPN from home to access company network folders.</p>
  
  <pre><code>Sub doit()
      If ConnectedToVPN Then
      ' run other code to access network folders and files...
      End if
  End Sub
  
  
  Function ConnectedToVPN() As Boolean
     Dim sComputer$, oWMIService, colItems, objItem
  
     ConnectedToVPN = False
     sComputer = "."
  
     Set oWMIService = GetObject("winmgmts:\\" &amp; sComputer &amp; "\root\CIMV2")
     Set colItems = oWMIService.ExecQuery("SELECT * FROM Win32_NetworkAdapterConfiguration", , 48)
  
      'Please check description of your VPN Connection by running command "ipconfig /all" on command-line.
  
      For Each objItem In colItems
          If (InStr(LCase(objItem.Description), "vpn")) Then
              ConnectedToVPN = objItem.IPEnabled
          End If
      Next objItem
  
      If (ConnectedToVPN) Then ConnectedToVPN = True
  
  End Function
  </code></pre>
  
  <p>But if i am in company office and connected to intranet using LAN cable or office WIFI, i don't need to connect to VPN. This way, i cannot make my code work.</p>
  
  <p>I tried the following but not giving me correct results:</p>
  
  <ul>
  <li>objItem.ServiceName</li>
  <li>objItem.DNSDomain</li>
  </ul>
  
  <p>So what <code>objItem properties</code> would determine that i am already connected to intranet via either an Office Wifi or Office LAN. e.g. properties to determine <code>State</code> and <code>type of Adapter</code> to which i am connected i.e. whether <code>Wifi</code>, <code>Ethernet</code> etc?</p>