none
How to determine whether the user is on site or not from an Office Add-In RRS feed

  • Question

  • Okay, so I have an add-in to Excel using VSTO and it works brilliantly allowing people to dump data into Excel from a database, format it and then put it back again.  However, if a user were to take their laptop home with them and then try to open Excel they will have a long pause as it tries to connect to a database that is no longer there, followed by some errors and a "funny looking" ribbon tab with half the buttons missing.

    This in itself isn't a problem.

    However, I have been thinking.  I have another application that uses a VBA macro to bring up a Data Form for users to enter data quickly using a tablet device when working off site and this looks awful, is written in Visual Basic, has clunky combo-boxes, has all the security issues that come with macros, etc. so fails on many counts.  In general users don't like using this application.

    What I would like is to get rid of the awful macro and replace it with a VSTO Add-In.  Users could then install the add-in on to their tablets and have a much slicker interface to enter data when working off site.  Basically I would use a Windows Form so it would look much, much better than anything I could ever do in native Excel.

    However, I don't like the idea of having two add-ins so I would like it if I could make my existing add-in more "aware" of where it is running.  If it is running on site then it will bring up all the tabs/ buttons, but if it is running off site it will recognise this, only bring up buttons related to the offsite Data Form and make no further attempts to connect to a database that isn't there.

    This might seem a little random, but the full process is as follows:
    - on site, the user plans a visit to a member site to collect data
    - on site, the user opens Excel, goes to the add-in ribbon tab and selects a member, year, location, etc.
    - on site, the user clicks a button to load base data into Excel (into a hidden sheet) from the database
    - now the user has a "primed" Excel workbook ready to take with them on their visits
    - off site, the user opens a form that uses this base data for product searches and also to populate drop-downs

    So the users will need to have both the add-in and the macro installed anyway.  It just seems to make more sense to give them an add-in and that will do both pieces of work?

    I could control this by trying to connect to the database and then remembering whether this worked or not.  But that sounds like a weak idea, it would mean waiting for a connection to time out and then hiding an error message.  If a user were on site and the database was taken off line temporarily then users would start to see the "offsite" version of the add-in which isn't ideal.

    I could ask the user when they launch Excel, but this seems very invasive; particularly because they might not even be using the add-in, maybe they just want to work on their personal accounts or record some random information?

    I could ask the user the first time they switch to the add-in ribbon tab.  I just don't like the idea of trusting users to know anything (even where they are).

    Ideally I would be able to identify that I am on a particular network but I have no idea how to proceed with this... any ideas out there?

    Wednesday, April 24, 2013 5:02 PM

Answers

  • Well I didn't have much luck here but I got the answer from a colleague:

    bool networkHere = System.Net.NetworkInformation.NetworkInterface.GetIsNetworkAvailable();

    • Marked as answer by Diksta Thursday, April 25, 2013 11:05 AM
    Thursday, April 25, 2013 10:12 AM

All replies

  • Well I didn't have much luck here but I got the answer from a colleague:

    bool networkHere = System.Net.NetworkInformation.NetworkInterface.GetIsNetworkAvailable();

    • Marked as answer by Diksta Thursday, April 25, 2013 11:05 AM
    Thursday, April 25, 2013 10:12 AM
  • Hi Diksta,

    I'm glad to hear that your issue has been resolved.

    Thank you for sharing your solution which might be very helpful to other community members.

    Have a nice day.


    Quist Zhang [MSFT]
    MSDN Community Support | Feedback to us
    Develop and promote your apps in Windows Store
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Thursday, April 25, 2013 12:18 PM
    Moderator