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(); 3 4810
<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.
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.
<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. This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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.
...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
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...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new...
| |