Solved

Why EXCEL wont Close after use in vb.net

Posted on 2007-03-21
3
313 Views
Last Modified: 2012-05-05
xls will not stop/end after use in vb.net
       
 
 
 I have asked this question before but still no answers.

I have an application (vb.net 2005) that use the following I then need to delete after it is finished doing what I am doing.. but I keep getting an error that it is still in use. and when I look at task manager processes there is still an excel app running, even though it is not in the current tasks.

PLEASE HELP HOW DO I REMOVE THE EXCEL FROM THE PROCESS!!!!!!!!!!!!

Imports VBIDE = Microsoft.Vbe.Interop

Imports Microsoft.Office.Core

Dim xlsApp As Excel.Application

Dim xlsWB As Excel.Workbook

Dim xlsSheet As Excel.Worksheet

Dim xlsCell As Excel.Range

xlsApp = New Excel.Application

xlsWB = xlsApp.Workbooks.Open(c:test.xls)

xlsSheet = xlsWB.Worksheets(1)

xlsCell = xlsSheet.Range("A1")

xlsWB.Close()

xlsApp.Quit()

System.Runtime.InteropServices.Marshal.ReleaseComObject(xlsSheet)

System.Runtime.InteropServices.Marshal.ReleaseComObject(xlsWB)

System.Runtime.InteropServices.Marshal.ReleaseComObject(xlsApp)

xlsWB = Nothing

xlsApp = Nothing

xlsSheet = Nothing

GC.Collect()

GC.WaitForPendingFinalizers()

GC.Collect()

GC.WaitForPendingFinalizers()
 
 
 
0
Comment
Question by:LeeHopkins
  • 2
3 Comments
 
LVL 10

Accepted Solution

by:
bhagavan2uday earned 125 total points
ID: 18769236
have closed the sheet also
0
 
LVL 21

Expert Comment

by:theGhost_k8
ID: 18769500
I hope this is Typo:-...Open(c:test.xls) <--  no "\"
you have to release all this objects

Dim xlsApp As Excel.Application
Dim xlsWB As Excel.Workbook
Dim xlsSheet As Excel.Worksheet
Dim xlsCell As Excel.Range

I believe you missed the last one.
0
 
LVL 21

Expert Comment

by:theGhost_k8
ID: 18777498
System.Runtime.InteropServices.Marshal.ReleaseComObject(xlsCell )
0

Featured Post

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

I think the Typed DataTable and Typed DataSet are very good options when working with data, but I don't like auto-generated code. First, I create an Abstract Class for my DataTables Common Code.  This class Inherits from DataTable. Also, it can …
Since .Net 2.0, Visual Basic has made it easy to create a splash screen and set it via the "Splash Screen" drop down in the Project Properties.  A splash screen set in this manner is automatically created, displayed and closed by the framework itsel…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

743 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now