Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming,microsoft.public.vb.general.discussion
external usenet poster
 
Posts: 97
Default Problem with Excel 2000 automation

Hello,
I do not have that problem when using Excel 2002 and up, but
when using Excel 2000 the problem is as follows:
Set moExcelApp = GetObject(, "Excel.Application")
If moExcelApp Is Nothing Then
Set moExcelApp = CreateObject("Excel.Application")
End If

When there is not Excel application running and the code above is executed,
the Excel.EXE starts as a process.
Later, when the user wants to open spreadsheet the spreadsheet will not
open (Excel 2000 only) and the only remedy is to terminate Excel.EXE process
using Task Manager.
How to prevent that situation?
Should I programmatically terminate Excel.EXE process or there is another
way?
Any ideas appreciated,
Jack


  #2   Report Post  
Posted to microsoft.public.excel.programming,microsoft.public.vb.general.discussion
external usenet poster
 
Posts: 3
Default Problem with Excel 2000 automation


"Jack" <replyto@it wrote in message
...
Hello,
I do not have that problem when using Excel 2002 and up, but
when using Excel 2000 the problem is as follows:
Set moExcelApp = GetObject(, "Excel.Application")
If moExcelApp Is Nothing Then
Set moExcelApp = CreateObject("Excel.Application")
End If

When there is not Excel application running and the code above is
executed, the Excel.EXE starts as a process.
Later, when the user wants to open spreadsheet the spreadsheet will not
open (Excel 2000 only) and the only remedy is to terminate Excel.EXE
process using Task Manager.
How to prevent that situation?
Should I programmatically terminate Excel.EXE process or there is another
way?
Any ideas appreciated,
Jack


I use code similar to:
==========
Set objExcel = CreateObject("Excel.Application")
Set objSheet = objExcel.ActiveWorkbook.Worksheets(1)

' Code to write to the spreadsheet.

' Save the spreadsheet and close the workbook.
strExcelPath = "c:\Myfolder\MyWork.xls"
objExcel.ActiveWorkbook.SaveAs strExcelPath
objExcel.ActiveWorkbook.Close

' Quit Excel.
objExcel.Application.Quit
========
If I'm only reading the spreadsheet I use:
=========
' Close workbook and quit Excel.
objExcel.ActiveWorkbook.Close
objExcel.Application.Quit
==========
If I fail to Quit, I must terminate the excel.exe process in task manager or
the spreadsheet is locked.

--
Richard Mueller
Microsoft MVP Scripting and ADSI
Hilltop Lab - http://www.rlmueller.net
--


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 97
Default Problem with Excel 2000 automation

Are you talking specifically about Excel 2000?
What is the cause of the spreadsheet lock? How to avoid it?
Why are you using Task Manager to terminate process?
Cannot it be done programmatically?
Thanks,
Jack

"Richard Mueller [MVP]" wrote in
message ...

"Jack" <replyto@it wrote in message
...
Hello,
I do not have that problem when using Excel 2002 and up, but
when using Excel 2000 the problem is as follows:
Set moExcelApp = GetObject(, "Excel.Application")
If moExcelApp Is Nothing Then
Set moExcelApp = CreateObject("Excel.Application")
End If

When there is not Excel application running and the code above is
executed, the Excel.EXE starts as a process.
Later, when the user wants to open spreadsheet the spreadsheet will not
open (Excel 2000 only) and the only remedy is to terminate Excel.EXE
process using Task Manager.
How to prevent that situation?
Should I programmatically terminate Excel.EXE process or there is another
way?
Any ideas appreciated,
Jack


I use code similar to:
==========
Set objExcel = CreateObject("Excel.Application")
Set objSheet = objExcel.ActiveWorkbook.Worksheets(1)

' Code to write to the spreadsheet.

' Save the spreadsheet and close the workbook.
strExcelPath = "c:\Myfolder\MyWork.xls"
objExcel.ActiveWorkbook.SaveAs strExcelPath
objExcel.ActiveWorkbook.Close

' Quit Excel.
objExcel.Application.Quit
========
If I'm only reading the spreadsheet I use:
=========
' Close workbook and quit Excel.
objExcel.ActiveWorkbook.Close
objExcel.Application.Quit
==========
If I fail to Quit, I must terminate the excel.exe process in task manager
or the spreadsheet is locked.

--
Richard Mueller
Microsoft MVP Scripting and ADSI
Hilltop Lab - http://www.rlmueller.net
--




  #4   Report Post  
Posted to microsoft.public.excel.programming,microsoft.public.vb.general.discussion
external usenet poster
 
Posts: 5,600
Default Problem with Excel 2000 automation

Following (tested in Word) works fine for me with XL2000 and am not aware of
any particular difference in behaviour between XL versions

Dim moExcelApp As Object

Sub StartXL()
Dim sMsg As String
On Error Resume Next
Set moExcelApp = GetObject(, "Excel.Application")
If moExcelApp Is Nothing Then
Set moExcelApp = CreateObject("Excel.Application")
sMsg = "new instance"
Else
sMsg = "existing instance"
End If

MsgBox sMsg
moExcelApp.Caption = "Hello"
On Error GoTo 0
moExcelApp.IgnoreRemoteRequests = True


' moExcelApp.Visible = True ' for testing
End Sub
Sub QuitXL()
Dim oWB As Object
On Error Resume Next

' careful - close all without saving - only for testing

' first destroy any object ref's to objects on sheets

moExcelApp.DisplayAlerts = False
For Each oWB In moExcelApp.Workbooks
oWB.Close False
Next

' destroy any sheet object ref's

moExcelApp.IgnoreRemoteRequests = False
moExcelApp.Quit

Set moExcelApp = Nothing

End Sub

Don't simply use the above as a template, particularly the
IgnoreRemoteRequests pair which you probably wouldn't want with GetObject
and not necessarily with CreateObject. But look into why I included it.

If you want an XL instance purely for your own purposes normally best not to
bother with getting any existing instance, create your own anew. If feasible
make it visible in case anything goes wrong, though there may be other good
reasons not to do that.

The important thing when quitting is to explicitly destroy all object refs
that are not about to go out of scope by themselves, in the order they were
created, eg

set moRng = Nothing
set moSht = Nothing
moWB.close ' false true saveas, whatever
set moWB = Nothing
moExcelApp.Quit
set moExcelApp = nothing

Regards,
Peter T



"Richard Mueller [MVP]" wrote in
message ...

"Jack" <replyto@it wrote in message
...
Hello,
I do not have that problem when using Excel 2002 and up, but
when using Excel 2000 the problem is as follows:
Set moExcelApp = GetObject(, "Excel.Application")
If moExcelApp Is Nothing Then
Set moExcelApp = CreateObject("Excel.Application")
End If

When there is not Excel application running and the code above is
executed, the Excel.EXE starts as a process.
Later, when the user wants to open spreadsheet the spreadsheet will not
open (Excel 2000 only) and the only remedy is to terminate Excel.EXE
process using Task Manager.
How to prevent that situation?
Should I programmatically terminate Excel.EXE process or there is

another
way?
Any ideas appreciated,
Jack


I use code similar to:
==========
Set objExcel = CreateObject("Excel.Application")
Set objSheet = objExcel.ActiveWorkbook.Worksheets(1)

' Code to write to the spreadsheet.

' Save the spreadsheet and close the workbook.
strExcelPath = "c:\Myfolder\MyWork.xls"
objExcel.ActiveWorkbook.SaveAs strExcelPath
objExcel.ActiveWorkbook.Close

' Quit Excel.
objExcel.Application.Quit
========
If I'm only reading the spreadsheet I use:
=========
' Close workbook and quit Excel.
objExcel.ActiveWorkbook.Close
objExcel.Application.Quit
==========
If I fail to Quit, I must terminate the excel.exe process in task manager

or
the spreadsheet is locked.

--
Richard Mueller
Microsoft MVP Scripting and ADSI
Hilltop Lab - http://www.rlmueller.net
--




Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Compatibility Excel 2002 and 2000 in automation Michael[_38_] Excel Programming 2 April 12th 05 10:34 AM
RP - Office 2000 automation parameters Access and excel Matt. Excel Programming 5 December 16th 03 07:55 PM
Excel 2000 Automation Error Felix[_2_] Excel Programming 0 September 18th 03 04:56 AM
Excel 2000 Automation Error Bob Enagonio Excel Programming 1 September 17th 03 07:25 PM
Excel 2000 Automation Error Felix[_2_] Excel Programming 0 September 17th 03 04:03 PM


All times are GMT +1. The time now is 06:35 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"