Open correct version of Excel in Word

G

GrannyM

I have Word 2003, Excel 2003 and as of today Excel 2007. In a Word macro, I
am using: Set myExcel = GetObject(, "Excel.application") and if that errors
because Excel isn't open, an error handler with: Set myExcel =
CreateObject("Excel.application")

Now when I run my Word macro even if I have Excel 2003 open, the GetObject
does not find that Excel is open and will go to the CreateObject and create
an instance of Excel using Excel 2007. Is there a way to force it to open
the spreadsheet in Excel 2003?
 
K

Karl E. Peterson

GrannyM said:
I have Word 2003, Excel 2003 and as of today Excel 2007. In a Word macro, I
am using: Set myExcel = GetObject(, "Excel.application") and if that errors
because Excel isn't open, an error handler with: Set myExcel =
CreateObject("Excel.application")

Now when I run my Word macro even if I have Excel 2003 open, the GetObject
does not find that Excel is open and will go to the CreateObject and create
an instance of Excel using Excel 2007. Is there a way to force it to open
the spreadsheet in Excel 2003?

If you're doing stuff like this, you really need to get into your
registry and snoop around a bit. There, you'll find entries under HKCR
for "Excel.Application", "Excel.Application.10" (2003) and
"Excel.Application.12" (2007). Under "Excel.Application", you'll see a
CLSID entry that will match one or the other of the other two CLSID
entries. Therein lies your answer, although from a sort of reverse
twist angle.
 
G

GrannyM

Thank you so much! I never even thought about looking in the Registry.
Under Excel.Application was a folder CurVer that said Excel.Application.12.
I changed that to 11 and now everything works!
 
K

Karl E. Peterson

GrannyM said:
Thank you so much! I never even thought about looking in the Registry.
Under Excel.Application was a folder CurVer that said Excel.Application.12.
I changed that to 11 and now everything works!

Heh, well, I'm not sure that was the intent of my advice, so I'd better
correct that quickly. As a COM programmer, you need to become familiar
with how objects are registered with the system, if you want to make
best use of them. Or, as in your case, if you want to use them in
non-standard ways.

The "Excel.Application" entry is really an alias that's pointing to the
"preferred" object of that sort. While "Excel.Application.12" is a
specific object (version 12) of that sort. I didn't mean you should go
in and change anything in the registry. Rather, I meant you should
look at what's available in the registry, and choose the object that's
best suited to your needs.

In other words, on a system with Office 2007 installed, these
statements are equivalent:

Set obj = CreateObject("Excel.Application")
Set obj = CreateObject("Excel.Application.12")

But there's no reason you couldn't use this instead, if you wanted to
call up Office 2003:

Set obj = CreateObject("Excel.Application.11")

Make sense?
 
T

Tony Jollans

In other words, on a system with Office 2007 installed, these statements
are equivalent:

Set obj = CreateObject("Excel.Application")
Set obj = CreateObject("Excel.Application.12")

But there's no reason you couldn't use this instead, if you wanted to call
up Office 2003:

Set obj = CreateObject("Excel.Application.11")

Make sense?

It makes perfect sense. Unfortunately it doesn't work :-( Office does its
own thing (as usual) and the CLSID under Excel.Application.11 and
Excel.Application.12 is the same. The only way (I know) to guarantee getting
a particular version is to Shell the executable.
 
K

Karl E. Peterson

Tony said:
It makes perfect sense. Unfortunately it doesn't work :-( Office does its own
thing (as usual) and the CLSID under Excel.Application.11 and
Excel.Application.12 is the same.

Hmmmm, this could be why I've always heard/understood that multiple
side-by-side installations didn't work.
The only way (I know) to guarantee getting
a particular version is to Shell the executable.

I suppose you could play around with altering the incorrect CLSID
entry? (Unless, and this would be truly evil, unless those idiots used
the same CLSID for both versions???)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top