Solved

Why EXCEL wont Close after use in vb.net

Posted on 2007-03-21
3
315 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

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Exit the loop 4 42
Creating a route in asp.net webforms 2 25
VB.Net - Get ColumnNames of SQL Table 4 11
VB.Net WebRequest Code from JSON curl 9 9
If you're writing a .NET application to connect to an Access .mdb database and use pre-existing queries that require parameters, you've come to the right place! Let's say the pre-existing query(qryCust) in Access takes a Date as a parameter and l…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
In a recent question (https://www.experts-exchange.com/questions/28997919/Pagination-in-Adobe-Acrobat.html) here at Experts Exchange, a member asked how to add page numbers to a PDF file using Adobe Acrobat XI Pro. This short video Micro Tutorial sh…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

770 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