Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
help !!!!.. Excel object not closing
Hi
I am writing an application using VB.NET and office 2003. I write some data into the Excel sheet using automation and then close it but, I can still see the excel.exe running in the task manager. .Please help me...:(( The code I am using is : Private Sub openreport() Dim table As DataTable = CType (dgresults.DataSource, DataSet).Tables(0) Dim colIndex As Int32 Dim rowIndex As Int32 Dim row As DataRow Dim col As DataColumn Try If Not (m_oExcelApp Is Nothing) Then CloseReportTemplate() End If m_oExcelApp = New Excel.ApplicationClass m_oExcelApp.Visible = False m_oBooks = m_oExcelApp.Workbooks m_oBook = m_oBooks.Open("d:\documents\Bol.xlt") m_oSheet = m_oBook.Worksheets(1) rowIndex = rowIndex + 2 For Each row In table.Rows rowIndex = rowIndex + 1 colIndex = 0 For Each col In table.Columns colIndex = colIndex + 1 m_oExcelApp.Cells(rowIndex, colIndex) = row(col.ColumnName).ToString() Next Next m_oBook.SaveAs("c:\test.xls") Catch oExc As Exception Response.Write(oExc.Message) Finally CloseReportTemplate() End Try End Sub Private Sub CloseReportTemplate() If Not (m_oBook Is Nothing) Then m_oBook.Close(True) End If If Not (m_oSheet Is Nothing) Then System.Runtime.InteropServices.Marshal.ReleaseComO bject (m_oSheet) m_oSheet = Nothing End If If Not (m_oBook Is Nothing) Then System.Runtime.InteropServices.Marshal.ReleaseComO bject (m_oBook) m_oBook = Nothing End If If Not (m_oBooks Is Nothing) Then System.Runtime.InteropServices.Marshal.ReleaseComO bject (m_oBooks) m_oBooks = Nothing End If If Not (m_oExcelApp Is Nothing) Then m_oExcelApp.Quit() System.Runtime.InteropServices.Marshal.ReleaseComO bject (m_oExcelApp) m_oExcelApp = Nothing End If End Sub Vishal |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
Closing workbooks w/o closing Excel | Excel Discussion (Misc queries) | |||
2 Label Options - Forms Object vs Control Box Object | Excel Discussion (Misc queries) | |||
Object Variable Not Set Error on Selection object | Excel Worksheet Functions | |||
Help on closing object properly | Excel Programming | |||
Range object to Array object conversion | Excel Programming |