We are creating a Windows Form application (C# or VB.NET) that needs to reference an Office 2003 or Office 2007 COM object, depending on the version of office installed. What is the best way to handle this scenario and reference the correct COM object at runtime?
R – Selecting Office 2003/2007 COM Object (Correct One) in Winforms Application
comms-officeofficedevwinforms
Related Topic
- R – Will upgrading Office from 2003 to 2007 break VB programs which use Excel through the COM interop
- R – Interop with Office 2003 and 2007
- .net – Office 2007/2003 VSTO Shared Add-In Design Query
- Vba – difference in VBA versions between office 2003 and 2007
- R – Office interop: developing with 2003 PIAs on a machine with Office 2007
Best Answer
Unless you want to use any of the newly added objects and methods of the Office 2007 object model, it is fine to build referencing the Office 2003 PIAs, just make sure the correct version of the PIAs is deployed on the target system:
Otherwise I would recommend you the following blog articles by Andrew Whitechapel: Can you build one add-in for multiple versions of Office? (See the BIG warning that this is not officially supported by Microsoft).
Another option where you do not need the PIAs (this makes deployment a lot easier) would be to use ComImport together with late binding. This is however slower than using the interop assemblies, but if the automation code is not on the fast path this might be a good solution. You'll find an explanation how to implement this in the same blog post: Add-ins for Multiple Office Versions without PIAs