Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
Rex Rex is offline
external usenet poster
 
Posts: 26
Default Excel Won't Quit

After running this code, Excel remains:
Dim XL As Excel.Application
Set XL = CreateObject("Excel.Application")
XL.Workbooks.Open "C:\TEMP\AnyOld.XLS"
XL.Workbooks.Item(1).Close False
XL.Quit
Set XL = Nothing
Also tried .Close True and tried omitting .Close call.

What am I missing?
Rex
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 15
Default Excel Won't Quit

Just do Application.Quit (without the XL object) and it will quit.

"Rex" wrote:

After running this code, Excel remains:
Dim XL As Excel.Application
Set XL = CreateObject("Excel.Application")
XL.Workbooks.Open "C:\TEMP\AnyOld.XLS"
XL.Workbooks.Item(1).Close False
XL.Quit
Set XL = Nothing
Also tried .Close True and tried omitting .Close call.

What am I missing?
Rex

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,253
Default Excel Won't Quit


you're using a mix of early and latebound code..
plus it may be easier to set a reference to the opened workbook
both the routines close completely on my machine..
(even if you set xl.Visible = TRUE
so you can test/see what's happening..)



Sub Early()
Dim XL As Excel.Application
Dim WB As Excel.Workbook
Set XL = New Excel.Application
Set WB = XL.Workbooks.Open("C:\temp\AnyOld.XLS")
WB.Close False
XL.Quit
Set XL = Nothing
End Sub

Sub Late()
Dim XL As Object
Dim WB As Object
Set XL = CreateObject("Excel.Application")
Set WB = XL.Workbooks.Open("C:\temp\Anyold.xls")
WB.Close False
XL.Quit
Set XL = Nothing
End Sub





--
keepITcool
| www.XLsupport.com | keepITcool chello nl | amsterdam


Rex wrote :

After running this code, Excel remains:
Dim XL As Excel.Application
Set XL = CreateObject("Excel.Application")
XL.Workbooks.Open "C:\TEMP\AnyOld.XLS"
XL.Workbooks.Item(1).Close False
XL.Quit
Set XL = Nothing
Also tried .Close True and tried omitting .Close call.

What am I missing?
Rex

  #4   Report Post  
Posted to microsoft.public.excel.programming
Rex Rex is offline
external usenet poster
 
Posts: 26
Default Excel Won't Quit

Hmmm. I tried replacing XL.Quit with Application.Quit, but Excel stays up
even after the program ends.

Rex

"Inbar" wrote:

Just do Application.Quit (without the XL object) and it will quit.

"Rex" wrote:

After running this code, Excel remains:
Dim XL As Excel.Application
Set XL = CreateObject("Excel.Application")
XL.Workbooks.Open "C:\TEMP\AnyOld.XLS"
XL.Workbooks.Item(1).Close False
XL.Quit
Set XL = Nothing
Also tried .Close True and tried omitting .Close call.

What am I missing?
Rex

  #5   Report Post  
Posted to microsoft.public.excel.programming
Rex Rex is offline
external usenet poster
 
Posts: 26
Default Excel Won't Quit

I tried both of your examples and in both cases, Excel remains in the process
list after my program ends. The fact that both of these as well as Inbar's
suggestions all fail makes me think there's something wrong in my
environment. In fact, the only way I've been able to get Excel to quit is to
*not* do the .Open. If I comment out the .Open and .Close lines, it works
fine. (Well, "work" is probably an exaggeration, but Excel goes away after
the Set XL=Nothing.)

Here's some more info, in case it means anything to anyone: I'm using VB
6.0 on XP SP2. Excel 2000 (9.0.6926 SP-3). The reference in my project is
to Microsoft Excel 9.0 Object Library.

Rex

"keepITcool" wrote:


you're using a mix of early and latebound code..
plus it may be easier to set a reference to the opened workbook
both the routines close completely on my machine..
(even if you set xl.Visible = TRUE
so you can test/see what's happening..)



Sub Early()
Dim XL As Excel.Application
Dim WB As Excel.Workbook
Set XL = New Excel.Application
Set WB = XL.Workbooks.Open("C:\temp\AnyOld.XLS")
WB.Close False
XL.Quit
Set XL = Nothing
End Sub

Sub Late()
Dim XL As Object
Dim WB As Object
Set XL = CreateObject("Excel.Application")
Set WB = XL.Workbooks.Open("C:\temp\Anyold.xls")
WB.Close False
XL.Quit
Set XL = Nothing
End Sub





--
keepITcool
| www.XLsupport.com | keepITcool chello nl | amsterdam


Rex wrote :

After running this code, Excel remains:
Dim XL As Excel.Application
Set XL = CreateObject("Excel.Application")
XL.Workbooks.Open "C:\TEMP\AnyOld.XLS"
XL.Workbooks.Item(1).Close False
XL.Quit
Set XL = Nothing
Also tried .Close True and tried omitting .Close call.

What am I missing?
Rex




  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,290
Default Excel Won't Quit

Rex,

There's probably something in the following...
'-------------------------------------------------------------------------------------------
Here are some general guidelines to use when automating Excel...
'Jim Cone - November 2004

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.aspx?scid=kb%3ben-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.aspx?scid=kb%3ben-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.aspx?scid=kb%3ben-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#

'-------------------------------------------------------------
Jim Cone
San Francisco, CA



"Rex" wrote in message ...
I tried both of your examples and in both cases, Excel remains in the process
list after my program ends. The fact that both of these as well as Inbar's
suggestions all fail makes me think there's something wrong in my
environment. In fact, the only way I've been able to get Excel to quit is to
*not* do the .Open. If I comment out the .Open and .Close lines, it works
fine. (Well, "work" is probably an exaggeration, but Excel goes away after
the Set XL=Nothing.)
Here's some more info, in case it means anything to anyone: I'm using VB
6.0 on XP SP2. Excel 2000 (9.0.6926 SP-3). The reference in my project is
to Microsoft Excel 9.0 Object Library.
Rex


-snip-
  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 15
Default Excel Won't Quit

OK, in this case - you would to "kill" the EXCEL process. You can do this
with simple C# code. Let me know if you want help.

"Rex" wrote:

I tried both of your examples and in both cases, Excel remains in the process
list after my program ends. The fact that both of these as well as Inbar's
suggestions all fail makes me think there's something wrong in my
environment. In fact, the only way I've been able to get Excel to quit is to
*not* do the .Open. If I comment out the .Open and .Close lines, it works
fine. (Well, "work" is probably an exaggeration, but Excel goes away after
the Set XL=Nothing.)

Here's some more info, in case it means anything to anyone: I'm using VB
6.0 on XP SP2. Excel 2000 (9.0.6926 SP-3). The reference in my project is
to Microsoft Excel 9.0 Object Library.

Rex

"keepITcool" wrote:


you're using a mix of early and latebound code..
plus it may be easier to set a reference to the opened workbook
both the routines close completely on my machine..
(even if you set xl.Visible = TRUE
so you can test/see what's happening..)



Sub Early()
Dim XL As Excel.Application
Dim WB As Excel.Workbook
Set XL = New Excel.Application
Set WB = XL.Workbooks.Open("C:\temp\AnyOld.XLS")
WB.Close False
XL.Quit
Set XL = Nothing
End Sub

Sub Late()
Dim XL As Object
Dim WB As Object
Set XL = CreateObject("Excel.Application")
Set WB = XL.Workbooks.Open("C:\temp\Anyold.xls")
WB.Close False
XL.Quit
Set XL = Nothing
End Sub





--
keepITcool
| www.XLsupport.com | keepITcool chello nl | amsterdam


Rex wrote :

After running this code, Excel remains:
Dim XL As Excel.Application
Set XL = CreateObject("Excel.Application")
XL.Workbooks.Open "C:\TEMP\AnyOld.XLS"
XL.Workbooks.Item(1).Close False
XL.Quit
Set XL = Nothing
Also tried .Close True and tried omitting .Close call.

What am I missing?
Rex


  #8   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,670
Default Excel Won't Quit

I'm experiencing the same issue, just through .Net Interop. I've also
followed Jim Cone's recommendations on the order of how you exit out, and it
doesn't work either. How do I kill a process in VB.Net?



"Inbar" wrote:

OK, in this case - you would to "kill" the EXCEL process. You can do this
with simple C# code. Let me know if you want help.

"Rex" wrote:

I tried both of your examples and in both cases, Excel remains in the process
list after my program ends. The fact that both of these as well as Inbar's
suggestions all fail makes me think there's something wrong in my
environment. In fact, the only way I've been able to get Excel to quit is to
*not* do the .Open. If I comment out the .Open and .Close lines, it works
fine. (Well, "work" is probably an exaggeration, but Excel goes away after
the Set XL=Nothing.)

Here's some more info, in case it means anything to anyone: I'm using VB
6.0 on XP SP2. Excel 2000 (9.0.6926 SP-3). The reference in my project is
to Microsoft Excel 9.0 Object Library.

Rex

"keepITcool" wrote:


you're using a mix of early and latebound code..
plus it may be easier to set a reference to the opened workbook
both the routines close completely on my machine..
(even if you set xl.Visible = TRUE
so you can test/see what's happening..)



Sub Early()
Dim XL As Excel.Application
Dim WB As Excel.Workbook
Set XL = New Excel.Application
Set WB = XL.Workbooks.Open("C:\temp\AnyOld.XLS")
WB.Close False
XL.Quit
Set XL = Nothing
End Sub

Sub Late()
Dim XL As Object
Dim WB As Object
Set XL = CreateObject("Excel.Application")
Set WB = XL.Workbooks.Open("C:\temp\Anyold.xls")
WB.Close False
XL.Quit
Set XL = Nothing
End Sub





--
keepITcool
| www.XLsupport.com | keepITcool chello nl | amsterdam


Rex wrote :

After running this code, Excel remains:
Dim XL As Excel.Application
Set XL = CreateObject("Excel.Application")
XL.Workbooks.Open "C:\TEMP\AnyOld.XLS"
XL.Workbooks.Item(1).Close False
XL.Quit
Set XL = Nothing
Also tried .Close True and tried omitting .Close call.

What am I missing?
Rex

  #9   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,670
Default Excel Won't Quit

I experienced the same issues. I'm using .Net Interop in VB.Net. I even
followed Jim Cone's post, but no help either. How do I kill a process/thread
in VB.Net?



"Inbar" wrote:

OK, in this case - you would to "kill" the EXCEL process. You can do this
with simple C# code. Let me know if you want help.

"Rex" wrote:

I tried both of your examples and in both cases, Excel remains in the process
list after my program ends. The fact that both of these as well as Inbar's
suggestions all fail makes me think there's something wrong in my
environment. In fact, the only way I've been able to get Excel to quit is to
*not* do the .Open. If I comment out the .Open and .Close lines, it works
fine. (Well, "work" is probably an exaggeration, but Excel goes away after
the Set XL=Nothing.)

Here's some more info, in case it means anything to anyone: I'm using VB
6.0 on XP SP2. Excel 2000 (9.0.6926 SP-3). The reference in my project is
to Microsoft Excel 9.0 Object Library.

Rex

"keepITcool" wrote:


you're using a mix of early and latebound code..
plus it may be easier to set a reference to the opened workbook
both the routines close completely on my machine..
(even if you set xl.Visible = TRUE
so you can test/see what's happening..)



Sub Early()
Dim XL As Excel.Application
Dim WB As Excel.Workbook
Set XL = New Excel.Application
Set WB = XL.Workbooks.Open("C:\temp\AnyOld.XLS")
WB.Close False
XL.Quit
Set XL = Nothing
End Sub

Sub Late()
Dim XL As Object
Dim WB As Object
Set XL = CreateObject("Excel.Application")
Set WB = XL.Workbooks.Open("C:\temp\Anyold.xls")
WB.Close False
XL.Quit
Set XL = Nothing
End Sub





--
keepITcool
| www.XLsupport.com | keepITcool chello nl | amsterdam


Rex wrote :

After running this code, Excel remains:
Dim XL As Excel.Application
Set XL = CreateObject("Excel.Application")
XL.Workbooks.Open "C:\TEMP\AnyOld.XLS"
XL.Workbooks.Item(1).Close False
XL.Quit
Set XL = Nothing
Also tried .Close True and tried omitting .Close call.

What am I missing?
Rex

  #10   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default Excel Won't Quit

I have the same problem and have tried all suggustions. Any other ideas will
be appreciated.

"Rex" wrote:

After running this code, Excel remains:
Dim XL As Excel.Application
Set XL = CreateObject("Excel.Application")
XL.Workbooks.Open "C:\TEMP\AnyOld.XLS"
XL.Workbooks.Item(1).Close False
XL.Quit
Set XL = Nothing
Also tried .Close True and tried omitting .Close call.

What am I missing?
Rex



  #11   Report Post  
Posted to microsoft.public.excel.programming
Rex Rex is offline
external usenet poster
 
Posts: 26
Default Excel Won't Quit

I've opened a support case with Microsoft on this. I'll let you know how it
turns out.

Rex

"Skeets" wrote:

I have the same problem and have tried all suggustions. Any other ideas will
be appreciated.

"Rex" wrote:

After running this code, Excel remains:
Dim XL As Excel.Application
Set XL = CreateObject("Excel.Application")
XL.Workbooks.Open "C:\TEMP\AnyOld.XLS"
XL.Workbooks.Item(1).Close False
XL.Quit
Set XL = Nothing
Also tried .Close True and tried omitting .Close call.

What am I missing?
Rex

  #12   Report Post  
Posted to microsoft.public.excel.programming
Rex Rex is offline
external usenet poster
 
Posts: 26
Default Excel Won't Quit

Microsoft analyzed this for me and determined that the problem was caused by
the Google Desktop Search Office Addin: A COM add-in is initially loaded and
assigns the reference to Excel or one of its members to a global object, the
reference isn't released so Excel continues to be a loaded process. This is
what is happening when Google Desktop Search tool is installed. This tool
doesn't release the object reference to the document (workbook).

I uninstalled Google Desktop Search and the problem went away.

I have provided this description to Google Desktop Feedback.

"Rex" wrote:

After running this code, Excel remains:
Dim XL As Excel.Application
Set XL = CreateObject("Excel.Application")
XL.Workbooks.Open "C:\TEMP\AnyOld.XLS"
XL.Workbooks.Item(1).Close False
XL.Quit
Set XL = Nothing
Also tried .Close True and tried omitting .Close call.

What am I missing?
Rex

  #13   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default Excel Won't Quit

Thanks Rex. I have managed to fix my problem. I was running the Excel 5.0
object so I changed it to the Excel 9.0 object and used the code in the
previous post and it took care of my problem.

"Rex" wrote:

Microsoft analyzed this for me and determined that the problem was caused by
the Google Desktop Search Office Addin: A COM add-in is initially loaded and
assigns the reference to Excel or one of its members to a global object, the
reference isn't released so Excel continues to be a loaded process. This is
what is happening when Google Desktop Search tool is installed. This tool
doesn't release the object reference to the document (workbook).

I uninstalled Google Desktop Search and the problem went away.

I have provided this description to Google Desktop Feedback.

"Rex" wrote:

After running this code, Excel remains:
Dim XL As Excel.Application
Set XL = CreateObject("Excel.Application")
XL.Workbooks.Open "C:\TEMP\AnyOld.XLS"
XL.Workbooks.Item(1).Close False
XL.Quit
Set XL = Nothing
Also tried .Close True and tried omitting .Close call.

What am I missing?
Rex

  #14   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Excel Won't Quit

Jim, your solution was right on the mark for my application.
I've been searching for information on how to release excel after my AutoCAD
to Excel application finished.
Avoiding Activesheet, ActiveCell, With, and Select and using the object
reference instead caused the application to be slightly slower but Excel
terminates every time!
Thanks

"Jim Cone" wrote:

Rex,

There's probably something in the following...
'-------------------------------------------------------------------------------------------
Here are some general guidelines to use when automating Excel...
'Jim Cone - November 2004

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.aspx?scid=kb%3ben-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.aspx?scid=kb%3ben-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.aspx?scid=kb%3ben-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#

'-------------------------------------------------------------
Jim Cone
San Francisco, CA



"Rex" wrote in message ...
I tried both of your examples and in both cases, Excel remains in the process
list after my program ends. The fact that both of these as well as Inbar's
suggestions all fail makes me think there's something wrong in my
environment. In fact, the only way I've been able to get Excel to quit is to
*not* do the .Open. If I comment out the .Open and .Close lines, it works
fine. (Well, "work" is probably an exaggeration, but Excel goes away after
the Set XL=Nothing.)
Here's some more info, in case it means anything to anyone: I'm using VB
6.0 on XP SP2. Excel 2000 (9.0.6926 SP-3). The reference in my project is
to Microsoft Excel 9.0 Object Library.
Rex


-snip-

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
can't quit excel maven Excel Discussion (Misc queries) 0 March 15th 07 12:31 AM
Excel won't quit JRS Excel Discussion (Misc queries) 1 September 27th 05 04:31 AM
Excel doesn't quit Jos Vens Excel Programming 2 February 27th 04 01:08 AM
Can't get Excel to quit Todd Waldron Excel Programming 10 November 22nd 03 03:19 PM
Excel won't quit Jeff[_23_] Excel Programming 0 October 24th 03 05:14 PM


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

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

About Us

"It's about Microsoft Excel"