ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   How to check for Internet connection (https://www.excelbanter.com/excel-programming/364481-how-check-internet-connection.html)

Vikram[_4_]

How to check for Internet connection
 
I am developing an add-in which uses web query to update script prices
from the website.
As an error handling routine, I want to make sure that no error is
flashed by excel if someone tries to update price when there is no
internet connection available.

So can anyone suggest me how I can do this?


keepITcool

How to check for Internet connection
 

Vikram, try following:

Note: The API function gives a bit more information, but I've only used
the essenstial "Offline/online flag INTERNET_CONNECTION_OFFLINE = &H20&

Option Explicit

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

Function IsOnLine() As Boolean
Dim lFlag As Long
Dim sName As String
sName = Space(1)
If InternetGetConnectedStateEx(lFlag, sName, 0&, 0&) Then
IsOnLine = Not (lFlag And &H20)
End If

End Function

--
keepITcool
| www.XLsupport.com | keepITcool chello nl | amsterdam


Vikram wrote in
groups.com

I am developing an add-in which uses web query to update script prices
from the website.
As an error handling routine, I want to make sure that no error is
flashed by excel if someone tries to update price when there is no
internet connection available.

So can anyone suggest me how I can do this?


Vikram[_4_]

How to check for Internet connection
 
Thanks a lot. It worked!!!!

keepITcool wrote:
Vikram, try following:

Note: The API function gives a bit more information, but I've only used
the essenstial "Offline/online flag INTERNET_CONNECTION_OFFLINE = &H20&

Option Explicit

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

Function IsOnLine() As Boolean
Dim lFlag As Long
Dim sName As String
sName = Space(1)
If InternetGetConnectedStateEx(lFlag, sName, 0&, 0&) Then
IsOnLine = Not (lFlag And &H20)
End If

End Function

--
keepITcool
| www.XLsupport.com | keepITcool chello nl | amsterdam


Vikram wrote in
groups.com

I am developing an add-in which uses web query to update script prices
from the website.
As an error handling routine, I want to make sure that no error is
flashed by excel if someone tries to update price when there is no
internet connection available.

So can anyone suggest me how I can do this?



Vikram[_4_]

How to check for Internet connection
 
Thanks a lot. It worked!!!!

keepITcool wrote:
Vikram, try following:

Note: The API function gives a bit more information, but I've only used
the essenstial "Offline/online flag INTERNET_CONNECTION_OFFLINE = &H20&

Option Explicit

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

Function IsOnLine() As Boolean
Dim lFlag As Long
Dim sName As String
sName = Space(1)
If InternetGetConnectedStateEx(lFlag, sName, 0&, 0&) Then
IsOnLine = Not (lFlag And &H20)
End If

End Function

--
keepITcool
| www.XLsupport.com | keepITcool chello nl | amsterdam


Vikram wrote in
groups.com

I am developing an add-in which uses web query to update script prices
from the website.
As an error handling routine, I want to make sure that no error is
flashed by excel if someone tries to update price when there is no
internet connection available.

So can anyone suggest me how I can do this?




All times are GMT +1. The time now is 07:13 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com