From: GrannyM on
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?
From: Karl E. Peterson on
GrannyM wrote:
> 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.

--
..NET: It's About Trust!
http://vfred.mvps.org


From: GrannyM on
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!

"Karl E. Peterson" wrote:

> GrannyM wrote:
> > 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.
>
> --
> ..NET: It's About Trust!
> http://vfred.mvps.org
>
>
> .
>
From: Karl E. Peterson on
GrannyM wrote:
> "Karl E. Peterson" wrote:
>> GrannyM wrote:
>>> 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.
>
> 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?

--
..NET: It's About Trust!
http://vfred.mvps.org


From: "Tony Jollans" My forename at my surname dot on
> 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.

--
Enjoy,
Tony

www.WordArticles.com

"Karl E. Peterson" <karl(a)exmvps.org> wrote in message
news:uc$9h775KHA.5464(a)TK2MSFTNGP05.phx.gbl...
> GrannyM wrote:
>> "Karl E. Peterson" wrote:
>>> GrannyM wrote:
>>>> 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.
>>
>> 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?
>
> --
> .NET: It's About Trust!
> http://vfred.mvps.org
>
>