VSTO & .NET & Excel

April 27, 2008

Check which Excel version is installed

Filed under: .NET & Excel — Dennis M Wallentin @ 4:31 pm

Whenever I need some enviroment information I always tries to read the wanted values from Windows registry.  In VB.NET this is as rather straightful process as we have access to the namespace “Microsoft.Win32′ which includes the class to work with the registry.

Recently I had a need to find out if Excel is installed and if so if the version is 2002 or later was available. Since I’m also trying to learn how to use regular expression I took this opportunity to use it.

The following code shows the function and how to get the wanted information from the registry:
 

The above approach works in both Windows XP and Windows Vista and it does not require that users must have administrative rights.

The code can also be downloaded as a textfile here.

Kind regards,
Dennis

Advertisements

10 Comments »

  1. Nice code Dennis…

    I’m never comfortable poking a stick into the Registry. I’m much happier when someone else does all the experimenting… So thanks for the code sample!

    It’s a good snippet to add to the collection. 🙂

    Comment by Mike Rosenblum — April 28, 2008 @ 12:03 am

  2. Hi Dennis. Interesting approach. It seems to me, however, that it is foolproof only if the user has one version of Excel installed. Otherwise it returns with the first version that matches the reg exp.

    I do something similar in a VB6 routine that installs the registry entries for an add-in. I use an array of (8, 9, 10, 11, 12) and loop through all elements of this array, so the installation keys are written for each installed version.

    – Jon

    Comment by jonpeltier — April 28, 2008 @ 2:24 am

  3. Mike,

    Thanks and when it comes to jus t reading information from the registry I find it quite safe 😉

    Jon,
    I believe it’s important to understand that .NET does not play according to the COM rules.

    In fact, MSFT recommend that only one version of Excel (i e Office) should be available on computers when having .NET solutions that target Excel.

    All third-part suppliers (including me) recommend as well to not having multiply versions installed, I e none support multiply versions.

    .NET & COM communicate via Primarily Interop Assemblies (PIA) and although it’s possible to have side-by-side PIAs versions installed in GAC only one version can be ‘active’ (to simplify it).

    I’m not sure which version is being active, either the first version installed or the last version installed (I have not test it and I have no intention to do it).

    What we get is an unpredictable situation as.NET solutions may or may not work with one or more versions of Excel and therefore the scenario with multiply versions of Excel is not a valid scenario for .NET solutions.

    It seems to be common among Excel developers to have multiply versions installed. However if You decide to develop with .NET then it’s a must to have only one version per configuration.

    The same is valid for end users who start to use .NET solutions.

    How common is it that end users have multiply versions installed?

    Kind regards,
    Dennis

    Comment by Dennis Wallentin — April 28, 2008 @ 2:14 pm

  4. Hi Dennis –

    Thanks for the admonishment 🙂 . Yes, I believe I’ve read about .Net not doing things the COM way. This may in fact be why I had problems with my earlier forays into VB.Net. I have often in the past had multiple Office installations side by side. This is common among devs, despite Microsoft’s caveats. There are generally not any major issues with doing this, other than some shared things being compromised (for example, the gallery of user-defined chart types).

    Lately I’ve installed VirtualPC, so my main environment has just Office 2003. For any other environment, I will customize a new VM. I have Office 2003 with different SPs, 2007 with different SPs, and 2002 with the latest SP. If I were to start doing .Net deveelopment again, I’d hide that in a VM so as not to mess up th environment that I use for my “real work”.

    FWIW, I think it’s probably rare for an end-user to have multiple Office versions in the same installation.

    Comment by jonpeltier — April 29, 2008 @ 1:48 am

  5. Jon,

    Thanks for the info.

    In general I think it’s good to have several configurations with different Office versions installed. I do regret that we face a situation where we need to have so many different versions + SP available…

    As for .NET it’s also good (in addition to the above) as we then can code against the earliest versions of .NET Framework we expect to target.

    My own configuration may look wired but works good for me:

    On my development machine Ubuntu is my main system and I use vmWare for all my Windows & Office configurations.

    I also use a laptop running a minimized Windows XP and vmWare. When I need to bring with me any customized solution I copy the vmWare configuration file from the development to the laptop.

    Upto this date I have never came across a situation where any end user runs more then one version of Office.

    Kind regards,
    Dennis

    Comment by Dennis Wallentin — April 29, 2008 @ 12:55 pm

  6. > Upto this date I have never came across a situation where any end user runs more then one version of Office

    I’ve seen this once at an educational institution – they had both Office 2003 & Office 2007. Maybe it’s their way of easing the transition for staff/students.

    Comment by Eric — April 30, 2008 @ 9:53 pm

  7. Eric,

    Thanks and it sounds reasonable that it’s due transition.

    Kind regards,
    Dennis

    Comment by Dennis Wallentin — May 1, 2008 @ 11:30 am

  8. “…both Office 2003 & Office 2007 …”

    Of the possible combinations of Excel versions, if one is 2007, it will have problems. I’ve had 2000, 2002, and 2003 on a single computer without (much) issue for years. I’ve had one with 2003 and 2007, and another with 2000 and 2007, and both had difficulties. I can’t really describe the problems now, it’s been a while since I uninstalled 2007, and the problems havee faded into dim memory.

    Comment by jonpeltier — May 1, 2008 @ 3:31 pm

  9. Hi Dennis, it’s very nice snippet that helps me for the fix in excel import problem. Thank you very much.

    Comment by Umasankar — November 19, 2010 @ 12:21 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 )

Twitter picture

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

Facebook photo

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

Google+ photo

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

Connecting to %s

Create a free website or blog at WordPress.com.

%d bloggers like this: