VSTO & .NET & Excel

August 4, 2009

Connected to the network?

Filed under: .NET & Excel, COM Add-ins, VSTO & Excel — Dennis M Wallentin @ 1:37 am

It has been a while since I last made a post here.  But I intend to get up to speed and publish on a more regular basis. Anyway, on the .NET platform and with VB.NET we can rather easy check if the computer we work on is connected to a network or not.

To know that information allows us:

  • To run methods that update workbooks with the latest data.
  • Run network located templates and individual workbooks.
  • Load network based add-ins.

Technically we will be using the My namespace to find out if the computer is connected or not.  More specifically we will use the  My.Computer namespace which provides methods to control the computer’s hardware and the system software.  Among other things, it allows us to work with the file system, clipboard, Windows Registry network printers, network connection and keyboard & mouse.

The following snippet code shows how we can use it to determine if the computer is connected to a network.



Because the property isAvailable only indicates if there is a network available or not we need to make sure that there is a connection to the network we actually want to access. In order to do so we use the Ping function to insure that the wanted remote location is available.

Kind regards,



  1. Hi Dennis,

    This is a good example of why we might want to use .Net over VBA.
    It’s so much simpler and faster that VBA would be at doing the same thing, not in all case of course, but at this it is! 😉


    Comment by Ross — August 4, 2009 @ 3:48 pm

    • Ross,

      Yes, that’s indeed true. I have some addititional posts about it in the pipeline.

      However, .NET solves many of the issues and shortcomings with COM but at the same it creates new issues.

      Kind regards,

      Comment by Dennis Wallentin — August 4, 2009 @ 6:45 pm

  2. Hi all

    See also this site

    Comment by Ron de Bruin — August 4, 2009 @ 7:18 pm

  3. Ron,

    Thanks for the link and I believe it’s the following page You refer to when it comes to VBA and classic VB:

    Kind regards,

    Comment by Dennis Wallentin — August 10, 2009 @ 4:48 pm

RSS feed for comments on this post. TrackBack URI

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

Blog at WordPress.com.

%d bloggers like this: