How to make Excel Process close by itself
-
Dim FN As String = Server.MapPath("\esmp\temp\" & Session.SessionID & ".xls") Dim xl As New Excel.Application Dim wk As Excel.Workbook = xl.Workbooks.Add() xl.Cells(2, 2) = "its ok" wk.Close(SaveChanges:=True, FileName:=FN) wk = Nothing xl.Quit() xl = Nothing ------------------------------- that was the coding I wrote in the button click event. It does work fine...but it is creating a separate process every time, the event is fired...and the process from task manager could not get deleted automatically. If I click on button 5 times....5 processes named as "EXCEL.EXE" are staying in the processes of TaskManager. So, How to make the process to close byitself after the completion of its work.
-
Dim FN As String = Server.MapPath("\esmp\temp\" & Session.SessionID & ".xls") Dim xl As New Excel.Application Dim wk As Excel.Workbook = xl.Workbooks.Add() xl.Cells(2, 2) = "its ok" wk.Close(SaveChanges:=True, FileName:=FN) wk = Nothing xl.Quit() xl = Nothing ------------------------------- that was the coding I wrote in the button click event. It does work fine...but it is creating a separate process every time, the event is fired...and the process from task manager could not get deleted automatically. If I click on button 5 times....5 processes named as "EXCEL.EXE" are staying in the processes of TaskManager. So, How to make the process to close byitself after the completion of its work.
The Excel process won't close until your app closes. You could go through the pain of coding a subroutine that forces the process closed, but there is no reason for it. You might want to consider setting up a global Excel object for the duration of your application. That way, the resources you use in Excel are available at any time and you only keep on instance of it open. When your application quits, so does Excel. RageInTheMachine9532