+ Reply to Thread
Results 1 to 12 of 12

Boolean function to return whether the PC is connected to the Internet?

  1. #1
    Valued Forum Contributor
    Join Date
    08-29-2012
    Location
    In lockdown
    MS-Off Ver
    Excel 2010 (2003 to 2016 but 2010 for choice)
    Posts
    1,766

    Boolean function to return whether the PC is connected to the Internet?

    I want a boolean function to return whether the PC is connected to the Internet. I have no idea how to start creating this. Could anyone please provide please?


    Reason:
    I have code that checks an online database and downloads data after the user presses a button.
    If the host computer is not currently connected to the net, I would like to display a message of my choice instead of trying to run the code.
    To determine whether to run my message or not, I need a function that will return TRUE/FALSE if the host PC is net connected or not.
    *******************************************************

    HELP WANTED! (Links to Forum threads)
    Trying to create reusable code for Custom Events at Workbook (not Application) level

    *******************************************************

  2. #2
    Forum Contributor
    Join Date
    07-27-2012
    Location
    California, USA
    MS-Off Ver
    Excel 2003
    Posts
    198

    Re: Boolean function to return whether the PC is connected to the Internet?

    I found a solution on ehow (dot com) and modified it
    to return True of False after testing for internet
    connectivity.
    Try it out.
    Please Login or Register  to view this content.

  3. #3
    Valued Forum Contributor
    Join Date
    08-29-2012
    Location
    In lockdown
    MS-Off Ver
    Excel 2010 (2003 to 2016 but 2010 for choice)
    Posts
    1,766

    Re: Boolean function to return whether the PC is connected to the Internet?

    +1 for trying. I'm afraid that this code isn't working for me. I keep getting a result of not connected. I think the problem could be to do with corporate restrictions on the computer I am testing this on. So I think I will need a solution that doesn't rely on the use of windows script or cmd. (Also the code takes 20 seconds to run so I will need a faster alternative solution).

  4. #4
    Forum Guru Kyle123's Avatar
    Join Date
    03-10-2010
    Location
    Leeds
    MS-Off Ver
    365 Win 11
    Posts
    7,239

    Re: Boolean function to return whether the PC is connected to the Internet?

    How are you connecting to the database? A more resilient method would be to check for a response from the database / website you're using. The problem with just checking with internet connectivity is that you are only checking half the path. You could be connected to the internet, but the remote database could be offline - so you need to check both. Checking for a response from the remote server would do this in one step.

  5. #5
    Forum Contributor
    Join Date
    07-27-2012
    Location
    California, USA
    MS-Off Ver
    Excel 2003
    Posts
    198

    Re: Boolean function to return whether the PC is connected to the Internet?

    It would be interesting to know if you get a different
    format in the response to a ping command. The solution works
    for me with Windows 7 and XP. To test this, open a DOS window
    and type "ping " (without the quotes), followed by a valid website name,
    including the dot com part.
    If the PC is connected to the internet, you should see a line that
    contains the text "Reveived = 4". If not, then that would explain
    why my code did not work.

  6. #6
    Valued Forum Contributor
    Join Date
    08-29-2012
    Location
    In lockdown
    MS-Off Ver
    Excel 2010 (2003 to 2016 but 2010 for choice)
    Posts
    1,766

    Re: Boolean function to return whether the PC is connected to the Internet?

    Quote Originally Posted by xLJer View Post
    If the PC is connected to the internet, you should see a line that
    contains the text "Reveived = 4". If not, then that would explain
    why my code did not work.
    Confirmed I got "received = 4"

  7. #7
    Forum Contributor
    Join Date
    07-27-2012
    Location
    California, USA
    MS-Off Ver
    Excel 2003
    Posts
    198

    Re: Boolean function to return whether the PC is connected to the Internet?

    That explains the difference between your ping results and mine:
    you get "received" and I get "Received". If you were to try my
    solution again, change
    Please Login or Register  to view this content.
    to
    Please Login or Register  to view this content.
    The process takes about 3 seconds on my home PC. If it takes you 20 seconds,
    you can probably thank your company network for that.

  8. #8
    Valued Forum Contributor
    Join Date
    08-29-2012
    Location
    In lockdown
    MS-Off Ver
    Excel 2010 (2003 to 2016 but 2010 for choice)
    Posts
    1,766

    Re: Boolean function to return whether the PC is connected to the Internet?

    Well done xlJer +1

    Dropping the first letter causes the function to work correctly.

  9. #9
    Valued Forum Contributor
    Join Date
    08-29-2012
    Location
    In lockdown
    MS-Off Ver
    Excel 2010 (2003 to 2016 but 2010 for choice)
    Posts
    1,766

    Re: Boolean function to return whether the PC is connected to the Internet?

    Quote Originally Posted by Kyle123 View Post
    How are you connecting to the database?
    XMLHTTP (Microsoft XML tool reference required)


    Quote Originally Posted by Kyle123 View Post
    The problem with just checking with internet connectivity is that you are only checking half the path. You could be connected to the internet, but the remote database could be offline - so you need to check both.
    I agree that what you are saying is 100% correct.
    However, for the purpose of this thread, I am not worried about the database going down. I am more concerned about the more common occurence of an end user using the XLSM and not realising that they need to be internet connected. So I am looking for a function that efficiently determines this so I can then show a reminder message to the end user.

  10. #10
    Valued Forum Contributor
    Join Date
    08-29-2012
    Location
    In lockdown
    MS-Off Ver
    Excel 2010 (2003 to 2016 but 2010 for choice)
    Posts
    1,766

    Re: Boolean function to return whether the PC is connected to the Internet?

    xLJer has provided a working solution however a
    Please Login or Register  to view this content.
    before & after running the code confirms that it is taking 19 seconds to run on the end user machines. (Probably because of excess corporate filtering and/or aggressive anti-virus ). Since I can't change the end users machines, I am looking for a much faster alternative to determine internet connectivity.
    Last edited by mc84excel; 06-18-2013 at 08:35 PM.

  11. #11
    Forum Guru Kyle123's Avatar
    Join Date
    03-10-2010
    Location
    Leeds
    MS-Off Ver
    365 Win 11
    Posts
    7,239

    Re: Boolean function to return whether the PC is connected to the Internet?

    However, for the purpose of this thread, I am not worried about the database going down. I am more concerned about the more common occurence of an end user using the XLSM and not realising that they need to be internet connected. So I am looking for a function that efficiently determines this so I can then show a reminder message to the end user.
    But tbh that only does solve half the problem, it's faster just to xml the data base, if it's there, the user is connected to the database AND the database is up. In your scenario, what happens if they are connected to the internet, but cannot connect to the database?

    If all you want to do is check internet connectivity, I'd hit google
    Last edited by Kyle123; 06-19-2013 at 01:39 AM.

  12. #12
    Valued Forum Contributor
    Join Date
    08-29-2012
    Location
    In lockdown
    MS-Off Ver
    Excel 2010 (2003 to 2016 but 2010 for choice)
    Posts
    1,766

    Re: Boolean function to return whether the PC is connected to the Internet?

    Solved!

    + = fast
    - = requires reference library (Microsoft XML)
    Attached Files Attached Files

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1