473,371 Members | 1,696 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,371 software developers and data experts.

excel reference remains open

using the code below (some parts not included), I create a new excel
workbook with spreadheets.
I then want to delete a spreadsheet, but a reference remains open and
excel stays in task manager when
the code highlighted below is used. can someone help me identify what
object remains open and
how to release that reference? thanks

using Excel = Microsoft.Office.Interop.Excel;

Excel.Application xl;
Excel.Worksheet sheet;
Excel.Workbooks wbs;

sheets added, etc

//////////////////// reference remains when this code is used
Excel.Workbook wb = xl.ActiveWorkbook;
Excel.Worksheet sheet = (Excel.Worksheet)wb.Sheets[1];
////////////////////

xl.Quit();
System.Runtime.InteropServices.Marshal.ReleaseComO bject(sheet);
sheet = null;
System.Runtime.InteropServices.Marshal.ReleaseComO bject(wb);
wb = null;
System.Runtime.InteropServices.Marshal.ReleaseComO bject(wbs);
wbs = null;
System.Runtime.InteropServices.Marshal.ReleaseComO bject(xl);
xl = null;
GC.Collect();
GC.WaitForPendingFinalizers();

Apr 17 '07 #1
3 4808
<pl*****************@yahoo.comwrote in message
news:11*********************@e65g2000hsc.googlegro ups.com...
using the code below (some parts not included), I create a new excel
workbook with spreadheets.
I then want to delete a spreadsheet, but a reference remains open and
excel stays in task manager when
the code highlighted below is used. can someone help me identify what
object remains open and
how to release that reference? thanks

using Excel = Microsoft.Office.Interop.Excel;

Excel.Application xl;
Excel.Worksheet sheet;
Excel.Workbooks wbs;

sheets added, etc

//////////////////// reference remains when this code is used
Excel.Workbook wb = xl.ActiveWorkbook;
Excel.Worksheet sheet = (Excel.Worksheet)wb.Sheets[1];
////////////////////

xl.Quit();
System.Runtime.InteropServices.Marshal.ReleaseComO bject(sheet);
sheet = null;
System.Runtime.InteropServices.Marshal.ReleaseComO bject(wb);
wb = null;
System.Runtime.InteropServices.Marshal.ReleaseComO bject(wbs);
wbs = null;
System.Runtime.InteropServices.Marshal.ReleaseComO bject(xl);
xl = null;
GC.Collect();
GC.WaitForPendingFinalizers();

You already posted the same question before, the answer remains the same, you need to
release all references to Excel objects before you Quit, also, you need to Close the
Workbook before Saving and you need to Save before Quitting.
It really makes no sense to post only part of the code, please post a small but complete
sample that illustrates the issue.
You also have to tell us in what context you are running this code, here I mean, from a
client or from a service like application.

Willy.

Apr 17 '07 #2
On Apr 17, 6:26 pm, "Willy Denoyette [MVP]"
<willy.denoye...@telenet.bewrote:
<pleaseexplaintom...@yahoo.comwrote in message

news:11*********************@e65g2000hsc.googlegro ups.com...


using the code below (some parts not included), I create a new excel
workbook with spreadheets.
I then want to delete a spreadsheet, but a reference remains open and
excel stays in task manager when
the code highlighted below is used. can someone help me identify what
object remains open and
how to release that reference? thanks
using Excel = Microsoft.Office.Interop.Excel;
Excel.Application xl;
Excel.Worksheet sheet;
Excel.Workbooks wbs;
sheets added, etc
//////////////////// reference remains when this code is used
Excel.Workbook wb = xl.ActiveWorkbook;
Excel.Worksheet sheet = (Excel.Worksheet)wb.Sheets[1];
////////////////////
xl.Quit();
System.Runtime.InteropServices.Marshal.ReleaseComO bject(sheet);
sheet = null;
System.Runtime.InteropServices.Marshal.ReleaseComO bject(wb);
wb = null;
System.Runtime.InteropServices.Marshal.ReleaseComO bject(wbs);
wbs = null;
System.Runtime.InteropServices.Marshal.ReleaseComO bject(xl);
xl = null;
GC.Collect();
GC.WaitForPendingFinalizers();

You already posted the same question before, the answer remains the same, you need to
release all references to Excel objects before you Quit, also, you need to Close the
Workbook before Saving and you need to Save before Quitting.
It really makes no sense to post only part of the code, please post a small but complete
sample that illustrates the issue.
You also have to tell us in what context you are running this code, here I mean, from a
client or from a service like application.

Willy.- Hide quoted text -

- Show quoted text -
sorry I left out this line sheet.Delete();

//////////////////// reference remains when this code is used
Excel.Workbook wb = xl.ActiveWorkbook;
Excel.Worksheet sheet = (Excel.Worksheet)wb.Sheets[1];
sheet.Delete();
////////////////////

there are no additional references using wb or sheet in the
application.
is there a (hidden?) reference in these 3 lines that isn't handled
here?
xl.Quit();
System.Runtime.InteropServices.Marshal.ReleaseComO bject(sheet);
sheet = null;
System.Runtime.InteropServices.Marshal.ReleaseComO bject(wb);
wb = null;
System.Runtime.InteropServices.Marshal.ReleaseComO bject(wbs);
wbs = null;
System.Runtime.InteropServices.Marshal.ReleaseComO bject(xl);
xl = null;
GC.Collect();
GC.WaitForPendingFinalizers();

and, no this is not the same question that wasn't answered before.
thanks anybody with constructive advice.
Apr 18 '07 #3
<pl*****************@yahoo.comwrote in message
news:11**********************@n76g2000hsh.googlegr oups.com...
On Apr 17, 6:26 pm, "Willy Denoyette [MVP]"
<willy.denoye...@telenet.bewrote:
><pleaseexplaintom...@yahoo.comwrote in message

news:11*********************@e65g2000hsc.googlegr oups.com...


using the code below (some parts not included), I create a new excel
workbook with spreadheets.
I then want to delete a spreadsheet, but a reference remains open and
excel stays in task manager when
the code highlighted below is used. can someone help me identify what
object remains open and
how to release that reference? thanks
using Excel = Microsoft.Office.Interop.Excel;
Excel.Application xl;
Excel.Worksheet sheet;
Excel.Workbooks wbs;
sheets added, etc
//////////////////// reference remains when this code is used
Excel.Workbook wb = xl.ActiveWorkbook;
Excel.Worksheet sheet = (Excel.Worksheet)wb.Sheets[1];
////////////////////
xl.Quit();
System.Runtime.InteropServices.Marshal.ReleaseComO bject(sheet);
sheet = null;
System.Runtime.InteropServices.Marshal.ReleaseComO bject(wb);
wb = null;
System.Runtime.InteropServices.Marshal.ReleaseComO bject(wbs);
wbs = null;
System.Runtime.InteropServices.Marshal.ReleaseComO bject(xl);
xl = null;
GC.Collect();
GC.WaitForPendingFinalizers();

You already posted the same question before, the answer remains the same, you need to
release all references to Excel objects before you Quit, also, you need to Close the
Workbook before Saving and you need to Save before Quitting.
It really makes no sense to post only part of the code, please post a small but complete
sample that illustrates the issue.
You also have to tell us in what context you are running this code, here I mean, from a
client or from a service like application.

Willy.- Hide quoted text -

- Show quoted text -

sorry I left out this line sheet.Delete();

//////////////////// reference remains when this code is used
Excel.Workbook wb = xl.ActiveWorkbook;
Excel.Worksheet sheet = (Excel.Worksheet)wb.Sheets[1];
sheet.Delete();
////////////////////

there are no additional references using wb or sheet in the
application.
is there a (hidden?) reference in these 3 lines that isn't handled
here?
xl.Quit();
System.Runtime.InteropServices.Marshal.ReleaseComO bject(sheet);
sheet = null;
System.Runtime.InteropServices.Marshal.ReleaseComO bject(wb);
wb = null;
System.Runtime.InteropServices.Marshal.ReleaseComO bject(wbs);
wbs = null;
System.Runtime.InteropServices.Marshal.ReleaseComO bject(xl);
xl = null;
GC.Collect();
GC.WaitForPendingFinalizers();

and, no this is not the same question that wasn't answered before.
thanks anybody with constructive advice.


Sorry, but you don't come up with a complete sample, how can we answer your question "is
there a (hidden?) reference in these 3 lines that isn't handled here?", if you don't post
the full code or at least a small but complete sample that illustrates the issue.
Also, please answer the question regarding the context and type of this application, is it a
console like a Windows like application, or is it something that runs from a Service? It's
important to answer these, before one can give "constructive advise".

Willy.


Apr 18 '07 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

13
by: Allison Bailey | last post by:
Hi Folks, I'm a brand new Python programmer, so please point me in the right direction if this is not the best forum for this question.... I would like to open an existing MS Excel spreadsheet...
3
by: Otie | last post by:
I found the following under the GetObject help notes and in the example for GetObject: "This example uses the GetObject function to get a reference to a specific Microsoft Excel worksheet...
3
by: Vagabond Software | last post by:
Scenario: The end-user selects File-Save from my applications (WinForm) menu, specifies a filename, and waits waits for my app to write the contents of a dataset to an Excel workbook. The...
11
by: Tim Marsden | last post by:
Hi, I have a routine which is call from a ASP.NET web form. This routine creates an excel application, opens a workbook , runs some code to update the workbook, saves it as HTML on the sever and...
2
by: Praveen K | last post by:
I have a problem in communicating between the C# and the Excel Interop objects. The problem is something as described below. I use Microsoft Office-XP PIA dll’s as these dll’s were been...
0
by: rhett | last post by:
howdy folks, first off, I'd like to not that I have browsed the forums and thanks to what I've found there I'm 80% through this problem, but the last part seems to be a profound obstacle and any...
1
by: garry.oxnard | last post by:
Can anyone help me to solve a problem which involves switching from Access to Excel (then back to Access) programatically please? I have an Excel template which, on open, also opens an Access...
0
by: blainegray | last post by:
Greetings This is one of those Access is not closing Excel problems. The first time through the code works fine. The second time there is a problem. After lots of combinations, I finally...
7
by: =?Utf-8?B?VGVycnkgSG9sbGFuZA==?= | last post by:
I have a vb.net app that opens an excel worksheet, reads data and then closes the sheet. Im noticing that the Excel process is still running after I have closed and disposed of my excel objects. ...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.