|
-
Mar 8th, 2004, 11:17 PM
#1
Thread Starter
Lively Member
How to close an Excel process 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.
-
Mar 9th, 2004, 08:53 AM
#2
Lively Member
The COM object has not been released properly.
Microsoft suggest this solution using the
System.Runtime.InteropServices.Marshal.ReleaseComObject method.
VB Code:
Private Sub yoursub()
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()
'use the NAR sub to release COM object
NAR(xl)
End Sub
Private Sub NAR(ByVal o As Object)
'* Procedure: NAR
'* Author: Microsoft
'* Description: This sub cleanly releases the COM Automation Object.
'* Source: [url]http://support.microsoft.com/?kbid=317109[/url]
Try
System.Runtime.InteropServices.Marshal.ReleaseComObject(o)
Catch
Finally
o = Nothing
End Try
End Sub
-
Mar 9th, 2004, 10:09 AM
#3
Thread Starter
Lively Member
Thank you very very much...
-
Mar 9th, 2004, 11:05 AM
#4
Lively Member
I actually know something!
Wow... so thats what it feels like.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|