Solved

Checking for Internet Connection

Posted on 2013-11-27
6
858 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 51

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
PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

 

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

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

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

How to quickly and accurately populate Word documents with Excel data, charts and images (including Automated Bookmark generation) David Miller (dlmille) Synopsis In this article you’ll learn how to use ExcelToWord! to copy data,charts, shapes …
Workbook link problems after copying tabs to a new workbook? David Miller (dlmille) Intro Have you either copied sheets to a new workbook, and after having saved and opened that workbook, you find that there are links back to the original sou…
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 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.

729 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