ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Excel process stays in memory after Using Quit Function (https://www.excelbanter.com/excel-programming/327357-excel-process-stays-memory-after-using-quit-function.html)

Metaphis

Excel process stays in memory after Using Quit Function
 
Ok, I'm not sure if its the right place to post that but I use VBScript
to Launch excel.. Start some functions that are in Excel spreadsheet
that use a DCOM object and Scripting.FileSystemObject. All the
references created in the macros are set to Nothing before terminating.
But when I do oXls.Quit Nothing happen. No error, Excel.exe just stay
open endlessly. Now the only way I've found I could really stop excel
would be to find excel in the process list and terminate it... Not
really elegant if you ask me. If anyone know how to force excel to quit
or to know why it didn't quit so I can debug it I would appreciate.

Thanks in Advance


Jim Cone

Excel process stays in memory after Using Quit Function
 
Here are some general guidelines to use when automating Excel...
Jim Cone
San Francisco, USA
'---------------------------------

1. Set a reference to the primary Excel objects used in your program.
Dim xlApp As Excel.Application
Dim WB As Excel.Workbook
Dim WS As Excel.Worksheet
Set xlApp = New Excel.Application
Set WB = xlApp.Workbooks.Add
Set WS = WB.Sheets(1)

Use the appropriate reference Every Time you make reference to a spreadsheet.
Do not use Range(xx) - use WS.Range(xx)
Cells should be WS.Cells(10, 20) or _
WS.Range(WS.Cells(10, 20), WS.Cells(20, 40))

2. Avoid the use of ActiveSheet, ActiveWorkbook, Selection etc.
Use your object references.

3. Avoid the use of the "With" construct.

4. Set all objects to Nothing in the proper order - child then parent.
Set WS = Nothing
WB.Close SaveChanges:=True 'your choice
Set WB = Nothing
xlApp.Quit
Set xlApp = Nothing

Violating any of these guidelines can leave "orphans" that still refer
to Excel and prevent the application from closing.
'------------------------------------------------------------

Articles dealing with unqualified references and automation
application not quitting.
1. 178510 - PRB: Excel Automation Fails Second Time Code Runs
http://support.microsoft.com/default...en-us%3b178510
Summary: While running code that uses Automation to control Microsoft Excel,
one of the following errors may occur: With Microsoft Excel 97 and later, you receive the error:
Run-time error '1004': Method '<name of method' of object '_Global' failed -or-...

2. 189618 - PRB: Automation Error Calling Unqualified Method or Property
http://support.microsoft.com/default...en-us%3b189618
Summary: While running code that uses Automation to control Microsoft Word 97, Word 2000, or Word 2002,
you may receive one of the following error messages:
Run-time error '-2147023174' (800706ba) Automation error -or- Run-time error '462': The remote server...

3. 199219 - XL2000: Automation Doesn't Release Excel Object from Memory
http://support.microsoft.com/default...;en-us;q199219
When you run a macro that uses automation to create a Microsoft Excel object (instance),
the Excel object does not exit from memory when you specify.
If you create another Excel object after quitting the first, a second instance is in memory.
This problem occurs when your macro uses a "WITH" statement that refers to the automation object.

4. 319832 - INFO: Error or Unexpected Behavior with Office Automation When You Use Early Binding in Visual Basic
http://support.microsoft.com/default...en-us%3b319832
Summary: When you automate a Microsoft Office application,
you may receive an error message or you may experience unexpected behavior, as follows.
You may receive one of the following error messages: Error 91: Object variable or With block variable not set....
5. 317109 - Visual Basic .Net & Visual C#
'-------------------------------------------------------------


"Metaphis" wrote in message ups.com...
Ok, I'm not sure if its the right place to post that but I use VBScript
to Launch excel.. Start some functions that are in Excel spreadsheet
that use a DCOM object and Scripting.FileSystemObject. All the
references created in the macros are set to Nothing before terminating.
But when I do oXls.Quit Nothing happen. No error, Excel.exe just stay
open endlessly. Now the only way I've found I could really stop excel
would be to find excel in the process list and terminate it... Not
really elegant if you ask me. If anyone know how to force excel to quit
or to know why it didn't quit so I can debug it I would appreciate.

Thanks in Advance


Fredrik Wahlgren

Excel process stays in memory after Using Quit Function
 

"Jim Cone" wrote in message
...
Here are some general guidelines to use when automating Excel...
Jim Cone
San Francisco, USA
'---------------------------------

1. Set a reference to the primary Excel objects used in your program.
Dim xlApp As Excel.Application
Dim WB As Excel.Workbook
Dim WS As Excel.Worksheet
Set xlApp = New Excel.Application
Set WB = xlApp.Workbooks.Add
Set WS = WB.Sheets(1)

Use the appropriate reference Every Time you make reference to a

spreadsheet.
Do not use Range(xx) - use WS.Range(xx)
Cells should be WS.Cells(10, 20) or _
WS.Range(WS.Cells(10, 20), WS.Cells(20, 40))

2. Avoid the use of ActiveSheet, ActiveWorkbook, Selection etc.
Use your object references.

3. Avoid the use of the "With" construct.

4. Set all objects to Nothing in the proper order - child then parent.
Set WS = Nothing
WB.Close SaveChanges:=True 'your choice
Set WB = Nothing
xlApp.Quit
Set xlApp = Nothing

Violating any of these guidelines can leave "orphans" that still refer
to Excel and prevent the application from closing.
'------------------------------------------------------------

Articles dealing with unqualified references and automation
application not quitting.
1. 178510 - PRB: Excel Automation Fails Second Time Code Runs
http://support.microsoft.com/default...en-us%3b178510
Summary: While running code that uses Automation to control Microsoft

Excel,
one of the following errors may occur: With Microsoft Excel 97 and later,

you receive the error:
Run-time error '1004': Method '<name of method' of object '_Global'

failed -or-...

2. 189618 - PRB: Automation Error Calling Unqualified Method or Property
http://support.microsoft.com/default...en-us%3b189618
Summary: While running code that uses Automation to control Microsoft Word

97, Word 2000, or Word 2002,
you may receive one of the following error messages:
Run-time error '-2147023174' (800706ba) Automation error -or- Run-time

error '462': The remote server...

3. 199219 - XL2000: Automation Doesn't Release Excel Object from Memory
http://support.microsoft.com/default...;en-us;q199219
When you run a macro that uses automation to create a Microsoft Excel

object (instance),
the Excel object does not exit from memory when you specify.
If you create another Excel object after quitting the first, a second

instance is in memory.
This problem occurs when your macro uses a "WITH" statement that refers to

the automation object.

4. 319832 - INFO: Error or Unexpected Behavior with Office Automation When

You Use Early Binding in Visual Basic
http://support.microsoft.com/default...en-us%3b319832
Summary: When you automate a Microsoft Office application,
you may receive an error message or you may experience unexpected

behavior, as follows.
You may receive one of the following error messages: Error 91: Object

variable or With block variable not set....
5. 317109 - Visual Basic .Net & Visual C#
'-------------------------------------------------------------


"Metaphis" wrote in message

ups.com...
Ok, I'm not sure if its the right place to post that but I use VBScript
to Launch excel.. Start some functions that are in Excel spreadsheet
that use a DCOM object and Scripting.FileSystemObject. All the
references created in the macros are set to Nothing before terminating.
But when I do oXls.Quit Nothing happen. No error, Excel.exe just stay
open endlessly. Now the only way I've found I could really stop excel
would be to find excel in the process list and terminate it... Not
really elegant if you ask me. If anyone know how to force excel to quit
or to know why it didn't quit so I can debug it I would appreciate.

Thanks in Advance


If you have followed the general guidelines here and Excel still doesn't
quit, check if you have the GoogleDesktop installed. It has this strange
side effect which prevents Excel from being shut down.

/Fredrik



Metaphis

Excel process stays in memory after Using Quit Function
 
Ok, I haven't found the problem exactly but it seems it was du to a
corrupted workbook. I simply copy/pasted the code in a new Workbook and
it worked...



All times are GMT +1. The time now is 06:26 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com