Microsoft Office Interop in a mixed Office 2003 / 2007 / 2010 environment
In a situation wher开发者_如何学Goe most of the users are using the latest version of MS Office, and a few are using older ones, Office 2003/2007, due to machine limitations, is there a way to properly use the Office Interop libraries (and not 3rd party assemblies) to allow the application to be deployed without installing an older version of Office into the 2010 machines?
We have the same case, I just used late binding .CreateObject("Excel.Application")
, the thing with late binding is that you won't have any intellisense, so the best approach for me is first to write the code on a class with Office.Interop.Excel referenced, after that, Copy all the codes to the other class which use late binding.
Well, don't know if anyone will still look at this but there it goes, works perfectly!
I did exactly that, programmed in a machine with Excel 2010 (only) and executed perfeclty in another machine with Excel 2003 (only). (Programmed using Visual Studio 2010)
Click in "add reference" at the solution explorer and go to the ".NET" section. There will be lots of Assmeblies including "Microsoft.Office.Interop.TheProgramYouWant". The secret is to choose the older version (12.0.0.0), not the newer (14.0.0.0).
It will come with the "copy local" and the "specific version" options both set to true (I didn't change that, but I don't know exaclty if changes something).
Use late binding because then you don't need to reference any Office dll's in project. Example for Outlook late binding:
Dim OutlApp As Object
Dim NewEmail As Object
OutlApp = CreateObject("Outlook.Application")
NewEmail = OutlApp.CreateItem(0)
精彩评论