The site is currently in read-only mode for maintenance. Posting of new items will be available again shortly.
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:
The following versions of Microsoft Office are detected:
- Office 95
- Office 97
- Office 2000
- Office XP
- Office 2003
- Office 2007
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).
- 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.
- 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 =
- 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 =
office Version will now be one of the following values:
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").
- 2006-12-04: Version 1.0 - Initial release.