LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default Excel.Application.Quit leaving Excel process stays active

Well here is another struggling developer!

The example below shows some code that works - case 1 and 5 and some code
that does not - case 2,3 and 4. Why do case 2 to 4 not work and what is the
workaround?

Private Sub NAR(ByVal o As Object)
Try
System.Runtime.InteropServices.Marshal.ReleaseComO bject(o)
Catch
Finally
o = Nothing
End Try
End Sub
Private Sub TestXLQuit(ByVal XLFile As String, ByVal myCase As Integer)
Dim myExcelApp As New Microsoft.Office.Interop.Excel.Application
Dim myWkbks As Microsoft.Office.Interop.Excel.Workbooks
Dim myWkb As Microsoft.Office.Interop.Excel.Workbook
Dim mySheet As Microsoft.Office.Interop.Excel.Worksheet
Try
myWkbks = myExcelApp.Workbooks
myWkbks.Open(XLFile)
myWkb = myWkbks(1)

Dim w As Integer

Select Case myCase
Case 1
'application closes as expected.
Case 2
'application does not close.
w = myWkb.Worksheets.Count
Case 3
'application does not close.
mySheet = myWkb.Worksheets.Item("Sheet1")
w = mySheet.Cells(10, 10).value
Case 4
'application does not close.
mySheet = myExcelApp.ActiveSheet
w = mySheet.Cells(10, 10).value
Case 5
'application closes as expected.
mySheet = myExcelApp.ActiveSheet
End Select


NAR(mySheet)
mySheet = Nothing
myWkb.Close(True)
NAR(myWkb)
myWkb = Nothing
NAR(myWkbks)
myWkbks = Nothing
myExcelApp.Quit()
NAR(myExcelApp)
myExcelApp = Nothing

Catch ex As Exception
Response.Write(ex.ToString)
End Try

End Sub



--
www.gandalfsolutions.co.nz
 
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
macro to close excel application other than application.quit mary Excel Programming 1 September 14th 04 03:43 PM
Quit Method do not kill excel process Rui Oliveira Excel Programming 2 January 16th 04 09:38 AM
Quit Method do not kill excel process Rui Oliveira Excel Programming 0 January 15th 04 04:51 PM
EXCEL.exe stays open after Quit method in an HTA myriams9 Excel Programming 5 December 4th 03 07:06 AM
How to Quit an Excel process? Joe Brown Excel Programming 0 October 1st 03 06:06 AM


All times are GMT +1. The time now is 12:33 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"