Excel interop. Choose version of Excel to launch

  • Thread starter Thread starter Tim Marsden
  • Start date Start date
T

Tim Marsden

Hi,
I am developing and application which automates Excel. I have both Excel
2003 and 2007 install on my development machine along with the PIAs. I have 2
versions of my app, one referencing the 2003 PIAs and one the 2007 PIAs.
When I run the 2007 version, when it instatiates the Excel.Application, Excel
2003 starts.

Any ideas on what I should do to ensure the correct version of Excel starts.
 
Hello Tim,

If it is just a problem on your development machine and not on your
client's machine then I would just re-install Office 2007 (I assume that
you installed Office 2003 after Office 2007). Then, it should
start being the current Office application. If you have the same problem
on your client's computer, then you could start Excel manually and then
use GetObject rather than CreateObject. However, this might
cause problems, if that specific office version is not installed. But if
you want to go that way, follow these steps:

1. You need to get the path from the registry
(For Office 2007:
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Office\12.0\Excel\InstallRoot). As
I don't have Office 2003 here, I'm not sure where the path might be
saved in the registry, but I think that it shouldn't be difficult to
figure that out... ;)

2. Start Excel.exe.

3. After Excel has started, use GetObject for your Excel automation.

Best regards,

Martin
 
Hi Martin,
Thanks for the reply.
I am only worried about development. The client will have a single version
of Excel installed.
I know I have to have to change the PIA references depending on the target
version, I just wanted to aviod having to used 2 machines, one with 2003
installed and one with 2007. It would be nice if I had some kind of 'mode' on
my pc, so I could switch between 2003 and 2007 as the default version.

regards
Tim
 
Back
Top