Microsoft Office Version Detector






4.55/5 (9 votes)
Programmatically determine the version of Microsoft Office applications
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
- 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
- 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"
- 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
- 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.