Click here to Skip to main content
Click here to Skip to main content

Microsoft Office Version Detector

, 3 Dec 2006
Rate this:
Please Sign up or sign in to vote.
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)

Share

About the Author

Warren Stevens
Software Developer (Senior)
Canada Canada
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).

Comments and Discussions

 
QuestionA question about office upgrade PinmemberMember 1055138126-Jan-14 19:48 
GeneralVB Version PinmemberDanielLey24-Jul-09 11:20 
GeneralFileVersionInfo Pinmemberluisnike1925-Mar-08 7:04 
GeneralRe: FileVersionInfo PinmemberWarren Stevens26-Mar-08 15:00 
Generaldetect the office version with vb.net Pinmemberrajneesh00729-Nov-07 21:53 
Questionversion of MS Office through .Net web Application 2003 Pinmemberazabaig2-Nov-07 23:25 
General.net PinmemberGary Howlett10-Feb-07 12:01 
GeneralRe: .net PinmemberWarren Stevens20-Feb-07 12:05 
GeneralUser Access PinmemberOleg A.Lukin4-Dec-06 22:02 
GeneralRe: User Access PinmemberWarren Stevens5-Dec-06 3:38 
GeneralSlight fix PinmemberBirgir K4-Dec-06 13:27 
GeneralRe: Slight fix PinmemberWarren Stevens4-Dec-06 14:52 

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.

| Advertise | Privacy | Mobile
Web03 | 2.8.140827.1 | Last Updated 3 Dec 2006
Article Copyright 2006 by Warren Stevens
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid