Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
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 |
#2
Posted to microsoft.public.excel.programming
|
|||
|
|||
Excel.Application.Quit leaving Excel process stays active
Don't have .net, so untried, but add
myWkb.Saved = True perhaps? -- HTH ------- Bob Phillips "Siggy" wrote in message ... 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 |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
macro to close excel application other than application.quit | Excel Programming | |||
Quit Method do not kill excel process | Excel Programming | |||
Quit Method do not kill excel process | Excel Programming | |||
EXCEL.exe stays open after Quit method in an HTA | Excel Programming | |||
How to Quit an Excel process? | Excel Programming |