I have recently developed a Windows Form application which has several datagrids. My client needs to export the data into Excel. They are using different versions of Excel (i.e 2003,2007,2010,2013) but I'm using Office 2013. I have used excel 2013 references
(Microsoft excel 15.0 object library)
in my program. Recently, my client reported that the export option was not working. From my investigation it seems that my application is working fine for those who are using Office 2013 but not working for previous Office versions.
What can I do to make sure my application works in older versions of Excel?
If you know all your users will have excel, you can convert your excel references to "Object"s instead of hardcoded excel objects and then remove the DLL references from your project. This will work will all versions of office, as long as you don't use some NEW function that is not in the older versions.
For example, instead of this:
Dim _xlApp As Excel.Application
Dim _xlBook As Excel.Workbook
Try this:
Dim _xlApp As Object 'Excel.Application
Dim _xlBook As Object 'Excel.Workbook
Everything works the same (except no intellisence) except for instantiation of the excel application:
_xlApp = CreateObject("Excel.Application") 'New Excel.Application
I have done it this way for 15 years without ever changing my code based on different versions.