Hello, Steve,
I copied the code that you posted into the click event of a button on an
otherwise empty form. I had to make a couple of obvious changes to
account for missing pieces, but otherwise I found that your code worked
fine for me. Excel disappeared from TM on the first round of GC. (For
reference, I have copied the code I was using below. I am using VB.net
2003 on W2K SP4.)
Perhaps there is something somewhere else that is keeping Excel open on
your system.
Cheers,
Randy
Private Sub Button1_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) _
Handles Button1.Click
Dim xlapp As Excel.Application
xlapp = CType(CreateObject("Excel.Application"), _
Excel.Application)
'''Dim wb As Excel.Workbook = xlapp.Workbooks.Open(fileName)
Dim wb As Excel.Workbook = _
xlapp.Workbooks.Open("J:\Test\ExcelTest\Test.xls")
Dim xlSheet As Excel.Worksheet
Dim currRow As Integer
xlSheet = wb.Worksheets(1)
'''currRow = PTLRecordNumber
currRow = 1
'''xlSheet.Cells(currRow, 1) = Me.LotNumber
'''xlSheet.Cells(currRow, 2) = Me.ScrewMachineNumber
'''xlSheet.Cells(currRow, 3) = Me.PartNumber
'''xlSheet.Cells(currRow, 4) = Me.PlatingDate
'''xlSheet.Cells(currRow, 5) = 0
'''xlSheet.Cells(currRow, 6) = Me.LoadSize
'''xlSheet.Cells(currRow, 7) = Me.FullLoad
'''xlSheet.Cells(currRow, 8) = Me.Mean
'''xlSheet.Cells(currRow, 9) = Me.Hi
'''xlSheet.Cells(currRow, 10) = Me.Low
'''xlSheet.Cells(currRow, 11) = Me.PLTankNumber
'''xlSheet.Cells(currRow, 12) = Me.BasketNumber
'''xlSheet.Cells(currRow, 13) = Me.CarrierNumber
'''xlSheet.Cells(currRow, 14) = Me.AdhesionTest
'''xlSheet.Cells(currRow, 15) = Me.SolderabilityTest
'''xlSheet.Cells(currRow, 16) = Me.OscilineNiTank
'''xlSheet.Cells(currRow, 17) = Me.Comments
xlSheet.Cells(currRow, 1) = 1.23
xlSheet.Cells(currRow, 2) = "AB.CD"
xlSheet.Cells(currRow, 3) = Now
'ss wb.SaveAs(fileName, Excel.XlFileFormat.xlExcel9795)
wb.Save()
wb.Close()
xlapp.Quit()
'ss xlApp.UserControl = True
'ss xlApp.Visible = True
'''Attempt to close excel - notorious problem with .net not
closing
'''all instances of Excel in task manager!!
System.Runtime.InteropServices.Marshal.ReleaseComObject(xlSheet)
System.Runtime.InteropServices.Marshal.ReleaseComObject(wb)
System.Runtime.InteropServices.Marshal.ReleaseComObject(xlapp)
xlapp = Nothing
''' wb = Nothing
''' xlSheet = Nothing
GC.Collect()
GC.WaitForPendingFinalizers()
'''GC.Collect()
'''GC.WaitForPendingFinalizers()
'''GC.Collect()
End Sub