Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Excel is not quiting in VB.NET 2

Status
Not open for further replies.

nacco

Programmer
Nov 5, 2003
8
NL
Hey all,

Is there any body in the world who can tell me why Excel is not quiting (still in task manager)
part of my code is:

public class Webform1
Public Shared xlApp As New Excel.Application
Public Shared xlBooks As Excel.Workbooks
Public Shared xlBook As Excel.Workbook
Public Shared xlSheet As Excel.Worksheet

function buttonGenerateFile
xlBooks = xlApp.Workbooks
xlBook = xlBooks.Add
xlBook.SaveAs(ExcelFileName)
xlSheet = xlBook.Worksheets(1)
...... fill data in excel file

try System.Runtime.InteropServices.Marshal.ReleaseComObject(xlSheet)
xlSheet = Nothing
xlBook.Close()
System.Runtime.InteropServices.Marshal.ReleaseComObject(xlBook)
xlBook = Nothing
xlBooks.Close()
System.Runtime.InteropServices.Marshal.ReleaseComObject(xlBooks)
xlBooks = Nothing
xlApp.Quit()
System.Runtime.InteropServices.Marshal.ReleaseComObject(xlApp)
xlApp = Nothing
Catch
End Try

Catch exception As Exception
MsgLabel.Text = exception.ToString()
Finally
' Invoke garbage collector before termination
System.GC.Collect()
System.GC.WaitForPendingFinalizers()
End Try

thanks in advance,

wim
 
Thanks mil2n,

but all thats mentioned on the microsoft support page is already covered here.

 
Rather than defing the Excel objects at class level, define them at Sub level otherwise (I believe) the object will persist with the class and you're not cleaning it up when the class is Dipsosed/exited, only in the Sub so you'll still have an instance flkoating around. Its still early though :)

Rhys
The use of COBOL cripples the mind; its teaching should, therefore, be regarded as a criminal offense Edsgar Dijkstra

Church of the Flying Spaghetti Monster
 
Thanks for your help, it's working now
 
a little star to thank rhys666

Christiaan Baes
Belgium

I just like this --> [Wiggle] [Wiggle]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top