Is Connected to Internet?

lonely

Board Regular
Joined
Feb 28, 2003
Messages
230
Hi All,
Please can someone let me know if its possible to determine using the VBA code whether Internet connection is available. If the connection is available, i wish to run a piece of code that I have written, otherwise i wish the program to exit.

Any useful leads will be appreciated.
Thanks a lot in advance!
Lonely
 

Excel Facts

Which Excel functions can ignore hidden rows?
The SUBTOTAL and AGGREGATE functions ignore hidden rows. AGGREGATE can also exclude error cells and more.
On way, from Hans Herber:

Option Explicit

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

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

Sub InternetConnection()
Dim bln As Boolean
bln = IsConnected
If bln Then
MsgBox "Yes, internet connection exists."
Else
MsgBox "No, internet connection does not exist."
End If
End Sub
 
Upvote 0
Hi Tom,
Thanks a lot for the code. However, since i would be distributing this to some of my team mates, i was wondering if we can make this independent of any dll.

I assume that the above code will not run in case the person does not have the dll installed.
Let me know if i misunderstood u.
Thanks
 
Upvote 0
Upvote 0
The dll is part of Internet Extensions for Win32 and avail on all Win OS so you should be ok if they run windows.
 
Upvote 0

Forum statistics

Threads
1,223,911
Messages
6,175,337
Members
452,636
Latest member
laura12345

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top