Click here to Skip to main content
Licence CPOL
First Posted 3 Dec 2006
Views 46,030
Downloads 833
Bookmarked 33 times

Microsoft Office Version Detector

By | 3 Dec 2006 | Article
Programmatically determine the version of Microsoft Office applications

Sample Image - OfficeVersion.png

Introduction

OfficeVersion is a simple C++ class to programmatically detect the presence, and version of the popular Microsoft Office applications.

Why would you want to do this? Perhaps you have an Excel-automation feature in your application that you want to Enable/Disable? Maybe your application uses a visual style that is similar to one of the Microsoft Office applications, and you want to change your interface to match the particular version of Office that the user has installed.

Applications and Versions

The following Microsoft Office applications are detected:

  • Word
  • Excel
  • Outlook
  • Access
  • PowerPoint
The following versions of Microsoft Office are detected:
  • Office 95
  • Office 97
  • Office 2000
  • Office XP
  • Office 2003
  • Office 2007

Multiple versions?

If there are multiple versions of an application installed, the version that is detected is the one that is "registered" (i.e. the version of the application that will open your file when you double-click the file).

Usage

  1. Add "OfficeVersion.h" to your project (only this one file is needed). Currently the code uses the MFC/ATL CString class, but this could easily be changed to another C++ string class.
    #include "OfficeVersion.h"
  2. The following example code checks for the version of Excel (Note: the bold parts of the text are just there to highlight particular parts of the code).
    OfficeVersion::eOfficeVersion excelVersion = 
    OfficeVersion::GetApplicationVersion(OfficeVersion::eOfficeApp_Excel); 
    // excelVersion will now be one of the following values: 
    // 
    // OfficeVersion::eOfficeVersion_Unknown,
                    // not found, or an error occurred 
    // OfficeVersion::eOfficeVersion_95 
    // OfficeVersion::eOfficeVersion_97 
    // OfficeVersion::eOfficeVersion_2000 
    // OfficeVersion::eOfficeVersion_XP 
    // OfficeVersion::eOfficeVersion_2003 
    // OfficeVersion::eOfficeVersion_2007 
    
  3. The following example code checks for the version of "Office" (note: the bold parts of the text are just there to highlight particular parts of the code).
    OfficeVersion::eOfficeVersion officeVersion = 
            OfficeVersion::GetOfficeVersion();
    //
    office Version will now be one of the following values:
    //
    // OfficeVersion::eOfficeVersion_Unknown, 
                    // not found, or an error occurred
    // OfficeVersion::eOfficeVersion_95
    // OfficeVersion::eOfficeVersion_97
    // OfficeVersion::eOfficeVersion_2000
    // OfficeVersion::eOfficeVersion_XP
    // OfficeVersion::eOfficeVersion_2003
    // OfficeVersion::eOfficeVersion_2007

Algorithm note

Since "Office" is a collection of applications, and not a single application itself, the algorithm for determining the presence and version of "Office" is to look through the set of Office applications, and use the first one found. The search is performed in order of the (approximate) popularity of the application (i.e. Word then Excel then Outlook then Access then PowerPoint).

How does it work?

The code is based on an outdated Microsoft knowledge base article Q247985 (the code in the knowledge base article does not work for Office 2003 or 2007). The code looks for a specific registry key which holds the version for each application (e.g. HKEY_CLASSES_ROOT/Excel.Application/CurVer for Excel) which contains the version encoded in a string ("Excel.Application.11" on my computer). The internal Microsoft version number (i.e. the "11" at the end of "Excel.Application.11" ) is then mapped to the external "marketing" name, that you will be more familiar with (e.g. the internal version "11" is more commonly known as "Office 2003").

History

  • 2006-12-04: Version 1.0 - Initial release.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

About the Author

Warren Stevens

Software Developer (Senior)

Canada Canada

Member

www.IconsReview.com[^]
Huge list of stock icon collections (both free and commercial)
 
The picture is from September 2006, after picking up a rental car at the airport in Denver, Colorado. I'm smiling in the picture, because I have yet to come to the realization that I just wasted 400 bucks ( because you don't really need a car in downtown Denver - you can just walk everywhere).

Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
You must Sign In to use this message board. (secure sign-in)
 
Search this forum  
 FAQ
    Noise  Layout  Per page   
  Refresh
GeneralVB Version PinmemberDanielLey11:20 24 Jul '09  
GeneralFileVersionInfo Pinmemberluisnike197:04 25 Mar '08  
GeneralRe: FileVersionInfo PinmemberWarren Stevens15:00 26 Mar '08  
Generaldetect the office version with vb.net Pinmemberrajneesh00721:53 29 Nov '07  
Questionversion of MS Office through .Net web Application 2003 Pinmemberazabaig23:25 2 Nov '07  
General.net PinmemberGary Howlett12:01 10 Feb '07  
GeneralRe: .net PinmemberWarren Stevens12:05 20 Feb '07  
GeneralUser Access PinmemberOleg A.Lukin22:02 4 Dec '06  
GeneralRe: User Access PinmemberWarren Stevens3:38 5 Dec '06  
GeneralSlight fix PinmemberBirgir K13:27 4 Dec '06  
GeneralRe: Slight fix PinmemberWarren Stevens14:52 4 Dec '06  

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Mobile
Web04 | 2.5.120517.1 | Last Updated 3 Dec 2006
Article Copyright 2006 by Warren Stevens
Everything else Copyright © CodeProject, 1999-2012
Terms of Use
Layout: fixed | fluid