![]() | |
![]() |
| | Thread Tools | Display Modes |
#1
| |||
| |||
|
#2
| |||
| |||
|
|
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 |
#3
| |||
| |||
|
|
Try: CreateObject("Excel.Application.11") |
#4
| |||
| |||
|
|
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 |
#5
| |||
| |||
|
|
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 |
#6
| |||
| |||
|
|
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 |
#7
| |||
| |||
|
|
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 |
![]() |
| Thread Tools | |
| Display Modes | |
| |