dbTalk Databases Forums  

Excel: Two Versions Installed, How To Instantiate Earlier Version?

comp.databases.ms-access comp.databases.ms-access


Discuss Excel: Two Versions Installed, How To Instantiate Earlier Version? in the comp.databases.ms-access forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
(PeteCresswell)
 
Posts: n/a

Default Excel: Two Versions Installed, How To Instantiate Earlier Version? - 11-06-2011 , 08:14 AM






My developer box now has Excel 11 and 12 installed on it.

The users, however, have only Excel 11 and the Access app they
are using is predicated on 11.

But when I'm trying to test on the developer box, I keep getting
12 when I instantiate Excel via the code shown below.

The Question:
Is there any way to force the code to select Excel 11 instead of
defaulting to the highest version?

Something with CreateObject? .... or maybe a different call?
================================================== =============
Public Function Excel_Start(ByRef theSS As Excel.Application) As
Boolean
3000 DebugStackPush mModuleName & ": Excel_Start: "
3001 On Error GoTo Excel_Start_err

' PURPOSE: - Start an instance of MS Excel or use an existing
instance
' - Leave "theSS" pointing to the Excel Basic engine
' behind the newly-opened document
' ACCEPTS: - Pointer to the spreadsheet TB used by calling
routine
' RETURNS: True/False depending on success
'
' NOTES: 1) We do not want to keep opening up new instances
of Excel every time this routine
' is called, so we do the "= Nothing" check to see
if theSS has already been set.
' OTHOH the user may have closed that instance of
Excel, leaving theSS pointing to
' NeverNeverLand. Experimentation shows that an
error 2753 is generated in this case.
' Hence the error trap and the "userClosedExcel"
switch.
'
'SAMPLE:
'
?SpreadSheetOpenExisting("D:\Dev\SEI\DataSource\Bu ySell.xls",
gExcelApp)

3002 Dim userClosedExcel As Long
Dim serverNotExist As Long
Dim okToProceed As Boolean

Const oleError = 2753
Const rpcServerUnavailable = -2147023174
Const remoteServerNotExist = 462
Const docAlreadyOpen = 1004

Excel_Start_loop:
' ---------------------------------------------------
' Create an instance of Excel

3010 If (theSS Is Nothing) Or (userClosedExcel = 1) Then
3011 Set theSS = CreateObject("Excel.Application")
'3012 With theSs
'3013 .Workbooks.Add
'3014 .ScreenUpdating = True
'3015 .Visible = True
'3016 End With
3019 End If

' ---------------------------------------------------
' Open up the spreadsheet


3999 Excel_Start = True

Excel_Start_xit:
DebugStackPop
On Error Resume Next
Exit Function

Excel_Start_err:
Select Case Err
Case 2772
MsgBox "Unable to locate Microsoft Excel program. Please
notify your administrator", 16, "Cannot Open MS Excel"
Resume Excel_Start_xit
Case oleError, rpcServerUnavailable
If userClosedExcel = 0 Then
userClosedExcel = userClosedExcel + 1
Resume Excel_Start_loop
Else
BugAlert True, "Unable to open MS Excel. Suspect
user may have closed existing instance."
Resume Excel_Start_xit
End If
Case remoteServerNotExist
If serverNotExist = 0 Then
serverNotExist = serverNotExist + 1
Set theSS = Nothing
Resume Excel_Start_loop
Else
BugAlert True, "Unable to open MS Excel. Suspect
user may have closed existing instance."
Resume Excel_Start_xit
End If

Case docAlreadyOpen
BugAlert True, ""

Case Else
BugAlert True, ""
Resume Excel_Start_xit
End Select
Resume Excel_Start_xit 'Shouldn't be needed, but just
in case.....
End Function
================================================== =============
--
PeteCresswell

Reply With Quote
  #2  
Old   
Stuart McCall
 
Posts: n/a

Default Re: Excel: Two Versions Installed, How To Instantiate Earlier Version? - 11-06-2011 , 10:47 AM






"(PeteCresswell)" <x@y.Invalid> wrote

Quote:
My developer box now has Excel 11 and 12 installed on it.

The users, however, have only Excel 11 and the Access app they
are using is predicated on 11.

But when I'm trying to test on the developer box, I keep getting
12 when I instantiate Excel via the code shown below.

The Question:
Is there any way to force the code to select Excel 11 instead of
defaulting to the highest version?

Something with CreateObject? .... or maybe a different call?
================================================== =============
Public Function Excel_Start(ByRef theSS As Excel.Application) As
Boolean
3000 DebugStackPush mModuleName & ": Excel_Start: "
3001 On Error GoTo Excel_Start_err

' PURPOSE: - Start an instance of MS Excel or use an existing
instance
' - Leave "theSS" pointing to the Excel Basic engine
' behind the newly-opened document
' ACCEPTS: - Pointer to the spreadsheet TB used by calling
routine
' RETURNS: True/False depending on success
'
' NOTES: 1) We do not want to keep opening up new instances
of Excel every time this routine
' is called, so we do the "= Nothing" check to see
if theSS has already been set.
' OTHOH the user may have closed that instance of
Excel, leaving theSS pointing to
' NeverNeverLand. Experimentation shows that an
error 2753 is generated in this case.
' Hence the error trap and the "userClosedExcel"
switch.
'
'SAMPLE:
'
?SpreadSheetOpenExisting("D:\Dev\SEI\DataSource\Bu ySell.xls",
gExcelApp)

3002 Dim userClosedExcel As Long
Dim serverNotExist As Long
Dim okToProceed As Boolean

Const oleError = 2753
Const rpcServerUnavailable = -2147023174
Const remoteServerNotExist = 462
Const docAlreadyOpen = 1004

Excel_Start_loop:
' ---------------------------------------------------
' Create an instance of Excel

3010 If (theSS Is Nothing) Or (userClosedExcel = 1) Then
3011 Set theSS = CreateObject("Excel.Application")
'3012 With theSs
'3013 .Workbooks.Add
'3014 .ScreenUpdating = True
'3015 .Visible = True
'3016 End With
3019 End If

' ---------------------------------------------------
' Open up the spreadsheet


3999 Excel_Start = True

Excel_Start_xit:
DebugStackPop
On Error Resume Next
Exit Function

Excel_Start_err:
Select Case Err
Case 2772
MsgBox "Unable to locate Microsoft Excel program. Please
notify your administrator", 16, "Cannot Open MS Excel"
Resume Excel_Start_xit
Case oleError, rpcServerUnavailable
If userClosedExcel = 0 Then
userClosedExcel = userClosedExcel + 1
Resume Excel_Start_loop
Else
BugAlert True, "Unable to open MS Excel. Suspect
user may have closed existing instance."
Resume Excel_Start_xit
End If
Case remoteServerNotExist
If serverNotExist = 0 Then
serverNotExist = serverNotExist + 1
Set theSS = Nothing
Resume Excel_Start_loop
Else
BugAlert True, "Unable to open MS Excel. Suspect
user may have closed existing instance."
Resume Excel_Start_xit
End If

Case docAlreadyOpen
BugAlert True, ""

Case Else
BugAlert True, ""
Resume Excel_Start_xit
End Select
Resume Excel_Start_xit 'Shouldn't be needed, but just
in case.....
End Function
================================================== =============
--
PeteCresswell
Try:

CreateObject("Excel.Application.11")

Reply With Quote
  #3  
Old   
(PeteCresswell)
 
Posts: n/a

Default Re: Excel: Two Versions Installed, How To Instantiate Earlier Version? - 11-06-2011 , 03:53 PM



Per Stuart McCall:
Quote:
Try:

CreateObject("Excel.Application.11")
Doesn't seem tb working.

The code compiles and it executes, as in

3011 Set theSS = CreateObject("Excel.Application.11")

but, pausing on the next line, theSS.Version = 12.
--
PeteCresswell

Reply With Quote
  #4  
Old   
Stuart McCall
 
Posts: n/a

Default Re: Excel: Two Versions Installed, How To Instantiate Earlier Version? - 11-06-2011 , 06:26 PM



"(PeteCresswell)" <x@y.Invalid> wrote

Quote:
Per Stuart McCall:

Try:

CreateObject("Excel.Application.11")

Doesn't seem tb working.

The code compiles and it executes, as in

3011 Set theSS = CreateObject("Excel.Application.11")

but, pausing on the next line, theSS.Version = 12.
--
PeteCresswell
Hmm. Thought that would have worked. But the
"Additional Notes" on this page:

http://support.microsoft.com/kb/292491

seems to indicate that this is not the case. It specifically warns
that doing it this way will not operate as expected. Quote:

"A common perception for Office Automation when you have multiple
versions of Office installed on a system is that you can dictate which
version loads by using a specific version-dependent PROGID (for
example, that "Excel.Application.9" loads Excel 2000,
"Excel.Application.10" loads Excel 2002 and "Excel.Application.11"
loads Office Excel 2003). However, this is not correct. Excel 2000 and
later versions of Excel share the same CLSID, so the version that
loads with these PROGIDs depends solely on which version was last
installed."

So maybe the only answer would be to use shell to open the specific version,
then use GetObject to connect to it. Not an ideal solution, but...

Reply With Quote
  #5  
Old   
agiamb
 
Posts: n/a

Default Re: Excel: Two Versions Installed, How To Instantiate Earlier Version? - 11-07-2011 , 07:35 AM



I used to have the same problem when I had multiple versions of Office
installed on my development machine. 2007 & 2010 create too many problems
with multiple versions, so I now keep only one Office version on my machine,
and use virtual machines for others.

Prior to switching to virtual machines, I would just re-register the
appropriate Excel version prior to working on a particular project.
While, I had found it elsewhere (an MS article), I used the shortcut
solution described in the following thread

http://www.vbforums.com/showthread.php?t=536308

Scroll down to #8

--

AG
Email: npATadhdataDOTcom


"(PeteCresswell)" <x@y.Invalid> wrote

Quote:
My developer box now has Excel 11 and 12 installed on it.

The users, however, have only Excel 11 and the Access app they
are using is predicated on 11.

But when I'm trying to test on the developer box, I keep getting
12 when I instantiate Excel via the code shown below.

The Question:
Is there any way to force the code to select Excel 11 instead of
defaulting to the highest version?

Something with CreateObject? .... or maybe a different call?
================================================== =============
Public Function Excel_Start(ByRef theSS As Excel.Application) As
Boolean
3000 DebugStackPush mModuleName & ": Excel_Start: "
3001 On Error GoTo Excel_Start_err

' PURPOSE: - Start an instance of MS Excel or use an existing
instance
' - Leave "theSS" pointing to the Excel Basic engine
' behind the newly-opened document
' ACCEPTS: - Pointer to the spreadsheet TB used by calling
routine
' RETURNS: True/False depending on success
'
' NOTES: 1) We do not want to keep opening up new instances
of Excel every time this routine
' is called, so we do the "= Nothing" check to see
if theSS has already been set.
' OTHOH the user may have closed that instance of
Excel, leaving theSS pointing to
' NeverNeverLand. Experimentation shows that an
error 2753 is generated in this case.
' Hence the error trap and the "userClosedExcel"
switch.
'
'SAMPLE:
'
?SpreadSheetOpenExisting("D:\Dev\SEI\DataSource\Bu ySell.xls",
gExcelApp)

3002 Dim userClosedExcel As Long
Dim serverNotExist As Long
Dim okToProceed As Boolean

Const oleError = 2753
Const rpcServerUnavailable = -2147023174
Const remoteServerNotExist = 462
Const docAlreadyOpen = 1004

Excel_Start_loop:
' ---------------------------------------------------
' Create an instance of Excel

3010 If (theSS Is Nothing) Or (userClosedExcel = 1) Then
3011 Set theSS = CreateObject("Excel.Application")
'3012 With theSs
'3013 .Workbooks.Add
'3014 .ScreenUpdating = True
'3015 .Visible = True
'3016 End With
3019 End If

' ---------------------------------------------------
' Open up the spreadsheet


3999 Excel_Start = True

Excel_Start_xit:
DebugStackPop
On Error Resume Next
Exit Function

Excel_Start_err:
Select Case Err
Case 2772
MsgBox "Unable to locate Microsoft Excel program. Please
notify your administrator", 16, "Cannot Open MS Excel"
Resume Excel_Start_xit
Case oleError, rpcServerUnavailable
If userClosedExcel = 0 Then
userClosedExcel = userClosedExcel + 1
Resume Excel_Start_loop
Else
BugAlert True, "Unable to open MS Excel. Suspect
user may have closed existing instance."
Resume Excel_Start_xit
End If
Case remoteServerNotExist
If serverNotExist = 0 Then
serverNotExist = serverNotExist + 1
Set theSS = Nothing
Resume Excel_Start_loop
Else
BugAlert True, "Unable to open MS Excel. Suspect
user may have closed existing instance."
Resume Excel_Start_xit
End If

Case docAlreadyOpen
BugAlert True, ""

Case Else
BugAlert True, ""
Resume Excel_Start_xit
End Select
Resume Excel_Start_xit 'Shouldn't be needed, but just
in case.....
End Function
================================================== =============
--
PeteCresswell

Reply With Quote
  #6  
Old   
(PeteCresswell)
 
Posts: n/a

Default Re: Excel: Two Versions Installed, How To Instantiate Earlier Version? - 11-07-2011 , 10:32 AM



Per agiamb:
Quote:
Prior to switching to virtual machines, I would just re-register the
appropriate Excel version prior to working on a particular project.
While, I had found it elsewhere (an MS article), I used the shortcut
solution described in the following thread

http://www.vbforums.com/showthread.php?t=536308

Scroll down to #8
That worked a-ok changing from 12 to 11 but, FWIW to anybody else
reading this thread, it did not work for 11 back to 12 on my box.
YYMV....

OTOH, there's no problem just explicitly starting 12 from
Windows' Start menu. Ditto 11. It's just that for now and
evermore, it looks like instantiating an Excel object will 11.

Personally, that solves my problem 100% for now.

Thanks for the fix.
--
PeteCresswell

Reply With Quote
  #7  
Old   
agiamb
 
Posts: n/a

Default Re: Excel: Two Versions Installed, How To Instantiate Earlier Version? - 11-07-2011 , 01:58 PM



Happy to help.

--

AG
Email: npATadhdataDOTcom


"(PeteCresswell)" <x@y.Invalid> wrote

Quote:
Per agiamb:
Prior to switching to virtual machines, I would just re-register the
appropriate Excel version prior to working on a particular project.
While, I had found it elsewhere (an MS article), I used the shortcut
solution described in the following thread

http://www.vbforums.com/showthread.php?t=536308

Scroll down to #8

That worked a-ok changing from 12 to 11 but, FWIW to anybody else
reading this thread, it did not work for 11 back to 12 on my box.
YYMV....

OTOH, there's no problem just explicitly starting 12 from
Windows' Start menu. Ditto 11. It's just that for now and
evermore, it looks like instantiating an Excel object will 11.

Personally, that solves my problem 100% for now.

Thanks for the fix.
--
PeteCresswell

Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.