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
Solved

Checking for Internet Connection

Posted on 2013-11-27
6
780 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 50

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
Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 

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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Suggested Solutions

This tutorial explains how to create a series of drop-down lists that are dependent upon prior selections to guide (“force”) the user to make the correct selection and reduce data errors within Microsoft Excel. Excel 2010 was used for this tutorial;…
Freeze panes is an option within all variants of Excel to enable parts of a sheet to remain stationary when the cursor is in another part of the sheet. This is a very useful feature which is overlooked or under used.
This Micro Tutorial will demonstrate how to create pivot charts out of a data set. I also added a drop-down menu which allows to choose from different categories in the data set and the chart will automatically update.
Many functions in Excel can make decisions. The most simple of these is the IF function: it returns a value depending on whether a condition you describe is true or false. Once you get the hang of using the IF function, you will find it easier to us…

828 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