Hi,
is there a way to dynamically referense an Excel object into my project according to the version of the MS office the target machine uses ?
My production pc uses Office 2003 whereas target machines might use Offiice 2000 or Office XP...
Thanks
Printable View
Hi,
is there a way to dynamically referense an Excel object into my project according to the version of the MS office the target machine uses ?
My production pc uses Office 2003 whereas target machines might use Offiice 2000 or Office XP...
Thanks
Whatever object library is available to you from your references selection will be what version you will be able to use in your application.
If you are using Office 2003, there should be backward compatibility with lower versions. Have you tried running your app on a 2000 box or XP yet to see if you do have a problem? (your original post did not specifically say that you are running into issues. The inference from your question is that you believe you might.)
Yes, there are a few things to change in your code:
* The first is to replace the Excel types with Object, so if you have:
you need to change it to:VB Code:
Dim xlApp as Excel.Application Dim xlBook as Excel.Workbook ...VB Code:
Dim xlApp as Object Dim xlBook as Object ...
* The next change is to replace the initialisation of the object, so if you have:
you should replace it with:VB Code:
Set xlApp = New Excel.Application
VB Code:
Set xlApp = CreateObject("Excel.Application")
* Remove "Excel object Library" from the list in Project References
* The final change is to replace any constants from the Excel library, or define them in your code (there is download at www.msdn.microsoft.com called wc0993.exe that has a module with them all defined, which you can simply add to your project).
U are absolutely spot on.
I think i might have problems.... that'w why I asked..
I will try to compile using Office 2000 reference and see if there is a problem with later versions.
I just wanted to know if someone knew something on the matter...
thanks
si_the_geek I will try that ......
it looks exectly what i was after .....
thanks
Not quite true I'm afraid, there were some changes in Office 2003 which mean initiating the object for earlier versions has some major issues, however once that is done almost everything seems ok.Quote:
Originally Posted by Hack
Using my method means that whatever version is installed (95/97 and up) can be used without any change to the code (of course any features added to Office XP will fail if you try them on Office 97).
Quote:
Originally Posted by Hack
Thanks for the info si, it has been awhile since I've done anything with any of the office products. I'm not running 2003. We still have the Office 2002 product suite. Were the changes you referenced first introduced in 2003, or might they be present in 2002 as well?Quote:
Originally Posted by si_the_geek
erm.. I can't remember, it hasn't been an issue for me as I have never been able to guarantee my users will have exactly the same versions (and don't want to re-compile a load of programs each time we upgrade anyway ;) ), so I've always used the method above.
I'm pretty sure that the issue can be spotted by the item that is added to an installation package, if there is "Excel.exe" (rather than a tlb) the issue arises.
I would recommend always using the method I posted, as it allows unexpected changes to occur in the installation base without effecting your programs ;)
Excellent advice!! (Who says you can't teach an old Hack new tricks! :) )Quote:
Originally Posted by si_the_geek