Solved

Checking for Internet Connection

Posted on 2013-11-27
6
685 Views
Last Modified: 2013-11-28
EE Pros,

I have a Macro that updates MSN Currency when fired.  



Is there a way to check to see that a connection exists and if not, notify the user that "No Internet Connection Detected".

Sub CurrencyUpdate()
Sheets("Currency").QueryTables(1).Refresh
End Sub

That's it!

Thank you in advance,

B.
0
Comment
Question by:Bright01
6 Comments
 
LVL 17

Expert Comment

by:Chris Millard
ID: 39680729
What you could do is use VBA to check to see if a URL is valid - see this post which contains an example  that may be of help:-

http://www.mrexcel.com/forum/excel-questions/567315-check-if-url-exists-so-then-return-true.html
0
 
LVL 18

Expert Comment

by:Steven Harris
ID: 39680852
You can use something like the following code:

Which in short says "If internet is active then refresh data, else notify user..."

Private Declare Function InternetGetConnectedState _
   Lib "wininet.dll" (ByRef dwflags As Long, _
   ByVal dwReserved As Long) As Long
Private Const INTERNET_CONNECTION_MODEM As Long = &H1
Private Const INTERNET_CONNECTION_LAN As Long = &H2
Private Const INTERNET_CONNECTION_PROXY As Long = &H4
Private Const INTERNET_CONNECTION_OFFLINE As Long = &H20
Function IsInternetConnected() As Boolean
    Dim L As Long
    Dim R As Long
    R = InternetGetConnectedState(L, 0&)
    If R = 0 Then
        IsInternetConnected = False
    Else
        If R <= 4 Then
            IsInternetConnected = True
        Else
            IsInternetConnected = False
        End If
    End If
End Function
Sub CurrencyUpdate()
    If IsInternetConnected() = True Then
        Sheets("Currency").QueryTables(1).Refresh
    Else
        MsgBox "No internet connection is detected!"
    End If
End Sub

Open in new window

0
 
LVL 48

Assisted Solution

by:Rgonzo1971
Rgonzo1971 earned 150 total points
ID: 39681046
Hi,

pls try (reference to MS XML )

On Error Resume Next
Dim request As MSXML2.XMLHTTP60
request.Open "http://money.msn.com/"
request.Send
Msgbox request.Status

Open in new window


Regards
0
Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

 

Author Comment

by:Bright01
ID: 39681081
Rgonzo and ThinkSpace,

Where do I put this code?  In the WS or a Module?

B.
0
 
LVL 18

Accepted Solution

by:
Steven Harris earned 350 total points
ID: 39681162
Worksheet is fine.

Just replace your code with the one I suggested to test it.

For Rgonzo's, you will need to add it to a current routine.
0
 

Author Closing Comment

by:Bright01
ID: 39683282
Thank you!  Both solutions work...... good teamwork guys.

B.
0

Featured Post

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Drop Down List with Unique/Distinct Values (enhancing the Combo-Box with a few steps and a little code) David miller (dlmille) Intro Have you ever created a data validation list from a database field or spreadsheet column (e.g., Zip Codes or Co…
This code takes an Excel list of URL’s and adds a header titled “URL List”. It then searches through all URL’s in column “A”, looking for duplicates. When a duplicate is found, it is moved to the top of the list. The duplicate URL’s are then highlig…
This Micro Tutorial demonstrates how to create Excel charts: column, area, line, bar, and scatter charts. Formatting tips are provided as well.
This Micro Tutorial will demonstrate on a Mac how to change the sort order for chart legend values and decrpyt the intimidating chart menu.

757 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now