This article discusses the general implications of building Automation clients that work with more than one version of Office and explains the differences that binding can make in these situations.
However, applications that are tested and compiled with the type libraries of more recent versions of the Office application may not work with earlier versions of Office. Office type libraries are not binary compatible and, with each new Office version, may be modified to include new functions and interfaces. Functionality is implemented among the members of the new version that is not included in the earlier version. New methods are added to the end of the list of functions for any particular object interface, so that the previous members are located in the correct place with respect to the beginning of the interface and can be reached by existing Automation code. Because earlier versions of Office do not know about these new members, they fail if you try to access them.
If you do need to use functionality in a newer version of Office, but you are developing a project that must work on systems that contain more than one version, you should use late binding to make the call. When you use late binding, you instruct your application to use IDispatch for a particular object's interface. GetIDsOfNames is used to locate the dispID of the specific member method you want to use, and Invoke is used to make the Automation call.
To summarize, if you are developing an Automation client that you intend to work with multiple versions of an Office application, you should:
- Reference the type library of the earliest version of the Office application you intend to Automate. -or-
- Use late binding.
For example, if you have an existing Microsoft Visual Basic project that was compiled on a computer with Microsoft Word 97, that project runs correctly against Word 97, Word 2000, Word 2002, Microsoft Office Word 2003, and Microsoft Office Word 2007. If you later install Word 2000, then the next time you open the Visual Basic project, the project reference auto-updates to the Word 2000 Object Library. If you then recompile the project using the Word 2000 library, the code may no longer work with Word 97. To correct this problem, clear the reference to the new library and explicitly browse for and select the older type library. Alternatively, you can use late binding so that this auto-update issue does not apply.
For additional information, click the following article number to view the article in the Microsoft Knowledge Base:
(c) Microsoft Corporation 2001, All Rights Reserved. Contributions by Chris Jensen, Microsoft Corporation.
Article ID: 244167 - Last Review: Mar 23, 2009 - Revision: 1