Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
No Name
 
Posts: n/a
Default 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
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Closing workbooks w/o closing Excel Barb in MD Excel Discussion (Misc queries) 3 February 15th 10 06:42 PM
2 Label Options - Forms Object vs Control Box Object Awrex Excel Discussion (Misc queries) 3 July 17th 09 07:10 PM
Object Variable Not Set Error on Selection object Jean Excel Worksheet Functions 3 July 24th 06 06:45 PM
Help on closing object properly Snedker[_2_] Excel Programming 4 December 26th 03 11:52 PM
Range object to Array object conversion Tom Ogilvy Excel Programming 0 August 1st 03 12:16 AM


All times are GMT +1. The time now is 08:29 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"