473,395 Members | 1,941 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,395 software developers and data experts.

Close Excel after use


My app read from Excel file using Excel's COM dll

I create Excel object by:

Excel.Application ExcelObj = new Excel.Application();

and next make it inivisible:
ExcelObj.Visible = false;

All works great, but I saw in Task Manager that "excel" process still
exist even my app closed.
Seems to my app create "excel" process and doesnt dispose it

How can I do that programically?

Rgs
Maciej

Nov 17 '05 #1
3 4081
Maciej,

You must call Quit before you release the reference to the Excel
application object. This causes Excel to shut down (it is an out of process
COM server) when you release the final reference. Once you call Quit, you
need to call the static ReleaseComObject method on the Marshal class to
release the reference.

You need to be careful if you use properties on the application object
(which I am sure you are) which return other objects. The object model is
such that most every object returned has a reference to the main application
object (so yours is not the only one). Because of this, you need to make
sure that you pass every object exposed through a property or returned
through a method to the ReleaseComObject method on the Marshal class. DON'T
do something like this:

// Set the value on a range.
ExcelObj.Workbooks.Item(1).Worksheets.Item(1).Cell s(1, 1).Value = "hello";

This causes SIX com objects to be exposed, most of which have a
reference to the Application object.

Now, if the instance of excel that you are using is pretty localized in
your app (you use it in the course of a method invocation, and don't hold
onto it for a long time), then you ^could^ get away with this, forcing a
garbage collection at the end of your method. However, this could have a
negative impact on your performance, so you would have to consider this
approach very carefully.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Maciej Pietruszka" <pa*****@o2.pl> wrote in message
news:11**********************@g44g2000cwa.googlegr oups.com...

My app read from Excel file using Excel's COM dll

I create Excel object by:

Excel.Application ExcelObj = new Excel.Application();

and next make it inivisible:
ExcelObj.Visible = false;

All works great, but I saw in Task Manager that "excel" process still
exist even my app closed.
Seems to my app create "excel" process and doesnt dispose it

How can I do that programically?

Rgs
Maciej

Nov 17 '05 #2
See:

Office application does not quit after automation from Visual Studio .NET
client
http://support.microsoft.com/default...;EN-US;Q317109

--
Best regards,

Carlos J. Quintero

MZ-Tools: Productivity add-ins for Visual Studio .NET, VB6, VB5 and VBA
You can code, design and document much faster.
Free resources for add-in developers:
http://www.mztools.com

"Maciej Pietruszka" <pa*****@o2.pl> escribió en el mensaje
news:11**********************@g44g2000cwa.googlegr oups.com...

My app read from Excel file using Excel's COM dll

I create Excel object by:

Excel.Application ExcelObj = new Excel.Application();

and next make it inivisible:
ExcelObj.Visible = false;

All works great, but I saw in Task Manager that "excel" process still
exist even my app closed.
Seems to my app create "excel" process and doesnt dispose it

How can I do that programically?

Rgs
Maciej

Nov 17 '05 #3
Yeah you helped me a lot.
Many thanx!

That was what I've looked for.

Rgs
Maciej

Nov 17 '05 #4

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

Similar topics

14
by: IanW | last post by:
I don't know if this is in the right place but.. I am writing a VB.Net Class Library which uses Excel to produce workbooks If I create an instance of Excel and then close it I can get .NET to...
2
by: Lorenzo Melato | last post by:
Hi everyone, I have a very strange problem. If I open a .NET application from EXCEL using SHELL function, when I close EXCEL, the EXCEL.EXE process remain active and I must close it by Task...
5
by: Richie | last post by:
I want to close excel application from C#, this is the piece of code I am trying "System.Runtime.InteropServices.Marshal.ReleaseComObject(excelApp);" GC.Collect(); It ain't working ! Any ideas...
0
by: Stewart Allen | last post by:
Hi there, I've got some code to open up an Excel workbook but what I want is for the code to pause until the Excel workbook is closed. Sub EditWorkbook(strFile as String) Dim xlApp As...
1
by: Gary Cobden | last post by:
Hi I have a routine that uses VBA to open a hidden occurence of Excel, and do background computations. However, in the event that the routine terminates abnormally, I have not been able to...
3
by: David Berman | last post by:
Hi, I've written an application to do a while bunch of Excel automation. I open a file, scan through all the worksheets, extract data, and then I try to close Excel. However, I can see that I'm...
5
by: Wenke Ji | last post by:
Hi I open a Excel workbook using below API: Set ExcelServer = CreateObject("EXCEL.Application") Set TargetWorkbook = ExcelServer.Workbooks.Open (CurrentBook) Befor the programm exit , I use...
4
by: Powerguy | last post by:
Hi all, I've spent countless hours trying to get this silly EXCEL process to close once I have used it. If anyone can help it would really REALLy be appreciated! Below is my code- Dim t As...
10
by: Hendri Adriaens | last post by:
Hi, I'm trying to automate the creation of an excel file via COM. I copied my code below. I read many articles about how to release the COM objects that I create. The code below runs just fine...
1
by: popsoftheyear | last post by:
I'm trying to automate some very simple things in excel, but have run into a roadblock (using c++). To detect excel closing, I just monitor the Excel Process using WaitForSingleObject. In order to...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
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...
0
Oralloy
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,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
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...
0
tracyyun
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...
0
agi2029
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 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.