View Single Post
  #3   Report Post  
Posted to microsoft.public.excel.programming
Robin Hammond[_2_] Robin Hammond[_2_] is offline
external usenet poster
 
Posts: 575
Default Internet connection?

Francis,

try these API calls. I played with this for a while myself until I found
this combination that seems to give a reliable result.

Option Explicit
Option Private Module

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

Private Declare Function InternetCheckConnection Lib "wininet.dll" _
Alias "InternetCheckConnectionA" (ByVal sUrl As String, _
ByVal lFlags As Long, ByVal lReserved As Long) As Long

Sub Test
If IsNetConnected = FALSE then Exit Sub
'do something internet related
End Sub

Public Function IsNetConnected() As Boolean
Dim lReturn As Long

IsNetConnected = InternetGetConnectedState(lReturn, 0)

'pick an IP or net address to go in the function call
If IsNetConnected = False Then _
IsNetConnected = InternetCheckConnection("http://www.yahoo.com", 1, 0)

If IsNetConnected = False Then _
Call MsgBox("You do not appear to have an active internet connection at
this time" _
& vbcrlf & vbcrlf & "Please connect to the internet then retry this
command", _
vbOKOnly + vbInformation, msgTitle)

End Function

HTH,

Robin Hammond
www.enhanceddatasystems.com

"Francis Ang" wrote in message
...
Using VBA codes I can now determine whether Microsoft Outlook or Outlook

Express is installed on a PC with the help from Michel Pierron. Can using
VBA codes determine whether a PC is connected to the internet or intranet?
Any help is very much appreciated.