Is there a way to check if the user is online or has some kind of internet connection

  • Thread starter Thread starter kenji4861
  • Start date Start date
K

kenji4861

I want to make the excel connect to a database, but when the user is not
online, it locks up.

I would like to know if there's a way to check if the user is online or
not. Thanks!
 
Try this
Copy all the code in a normal mudule

Public Declare Function InternetGetConnectedState _
Lib "wininet.dll" (lpdwFlags As Long, _
ByVal dwReserved As Long) As Boolean

Function IsConnected() As Boolean
Dim Stat As Long
IsConnected = (InternetGetConnectedState(Stat, 0&) <> 0)
End Function


Sub Test()
'stolen from Chip Pearson
If IsConnected = True Then
MsgBox " you are online"
Else
MsgBox "You can't use this subroutine because you are not online"
End If
End Sub
 
Definitely. Courtesy of Randy Birch's http://www.mvps.org/vbnet/

Option Explicit

Public Declare Function InternetGetConnectedState _
Lib "wininet" _
(ByRef dwFlags As Long, _
ByVal dwReserved As Long) As Long

Public Function IsNetConnectOnline() As Boolean
IsNetConnectOnline = InternetGetConnectedState(0&, 0&)
End Function

Sub Test()
MsgBox IsNetConnectOnline, , "Internet ?"
End Sub
 
Two possible downfalls to this approach.
IE5 is required(which is probably not a big deal).
If you're on a LAN , InternetGetConnectedState will always return
true(whether or not you actually have a active internet connection)
 
Thank you so much guys, this is so much better than waiting for the
server to return an error code. =)
 
Back
Top