Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Checking for Internet Connection

Posted on 2013-11-27
6
Medium Priority
?
987 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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 53

Assisted Solution

by:Rgonzo1971
Rgonzo1971 earned 600 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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

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 1400 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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Some code to ensure data integrity when using macros within Excel. Also included code that helps secure your data within an Excel workbook.
Access developers frequently have requirements to interact with Excel (import from or output to) in their applications.  You might be able to accomplish this with the TransferSpreadsheet and OutputTo methods, but in this series of articles I will di…
The viewer will learn how to use a discrete random variable to simulate the return on an investment over a period of years, create a Monte Carlo simulation using the discrete random variable, and create a graph to represent the possible returns over…
This Micro Tutorial demonstrates in Microsoft Excel how to consolidate your marketing data by creating an interactive charts using form controls. This creates cool drop-downs for viewers of your chart to choose from.

610 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