tylee Posted June 4, 2003 Posted June 4, 2003 (edited) Hi I have a .net project written in vb.net and i am having a problem killing ALL instances of the excel process in the task manager. I had this problem with a windows service written in vb.net but I have managed to fix that problem but the same code doesn't fix the problem I am having in my website The Code: Dim exObj As New Excel.Application() Dim exWorksheet As Excel.Worksheet Dim exWorkbook As Excel.Workbook exWorkbook = exObj.Workbooks.Open(("Template.xlt") exWorksheet = exWorkbook.Worksheets(1) 'Code in here which writes to the excel file and saves it for furture use 'attempts to close the excel process exWorkbook.Close() exObj.Workbooks.Close() exObj.Application.Quit() exObj.Quit() exWorksheet = Nothing exWorkbook = Nothing exObj = Nothing GC.Collect() GC.WaitForPendingFinalizers() if anyone can help it would be much appreciated Edited June 4, 2003 by tylee Quote
*Gurus* Derek Stone Posted June 4, 2003 *Gurus* Posted June 4, 2003 This problem is addressed here: http://www.xtremedotnettalk.com/showthread.php?s=&threadid=72211#post365760 Quote Posting Guidelines
tylee Posted June 4, 2003 Author Posted June 4, 2003 Here is my working code which opens the file, changes it and saves it. I finally got it to destroy the process with the help of the previous post. Dim MyExcel As New Excel.Application() Dim oWorkbooks As Excel.Workbooks = MyExcel.Workbooks Dim theWorkbook As Excel.Workbook = oWorkbooks.Add Dim oSheet As Excel.Worksheet theWorkbook = oWorkbooks.Open("C:\TEST.xls") oSheet = MyExcel.ActiveSheet() 'ALTER THE WORKSHEET HERE theWorkbook.Save() theWorkbook.Close() MyExcel.Quit() oSheet = Nothing theWorkbook = Nothing oWorkbooks = Nothing MyExcel = Nothing GC.Collect() GC.WaitForPendingFinalizers() Quote
screechowl Posted July 8, 2003 Posted July 8, 2003 I've been having the same problem with Excel hanging processes. I copied and pasted the exact code below and it still hangs the process. I've also tried working with the "Process" object, but I get an Access denied error. Any ideas? This is holding up my project big time.... Quote
WebJumper Posted July 8, 2003 Posted July 8, 2003 Following should work: MyExcel.Quit(); System.Runtime.InteropServices.Marshal.ReleaseComObject(MyExcel); MyExcel = null; But you have to do this with all your little objects (like Excel.Range, Excel.Cell etc.) When you clean all this objects, your Excel process should end. Woked for me fine!!! Regards, Stefan Quote
screechowl Posted July 9, 2003 Posted July 9, 2003 I agree that this works in a VB.net application, but I can't seem to get it to work in ASP.net. Would there be any difference with that? Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.