473,789 Members | 2,728 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Close Excel after use


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

I create Excel object by:

Excel.Applicati on ExcelObj = new Excel.Applicati on();

and next make it inivisible:
ExcelObj.Visibl e = 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 4107
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 ReleaseComObjec t 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 ReleaseComObjec t method on the Marshal class. DON'T
do something like this:

// Set the value on a range.
ExcelObj.Workbo oks.Item(1).Wor ksheets.Item(1) .Cells(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.co m

"Maciej Pietruszka" <pa*****@o2.p l> wrote in message
news:11******** **************@ g44g2000cwa.goo glegroups.com.. .

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

I create Excel object by:

Excel.Applicati on ExcelObj = new Excel.Applicati on();

and next make it inivisible:
ExcelObj.Visibl e = 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.p l> escribió en el mensaje
news:11******** **************@ g44g2000cwa.goo glegroups.com.. .

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

I create Excel object by:

Excel.Applicati on ExcelObj = new Excel.Applicati on();

and next make it inivisible:
ExcelObj.Visibl e = 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
2712
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 destroy the instance of Excel, however as soon as I try to add a workbook and then end then close Excel the instance will not close Code is included below Has anyone else experienced this What is going wrong Sub foo_Works( Dim xl As...
2
2095
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 manager. If I open a normal application (I.E. Notepad.exe) in the same manner, I have no problem.
5
23171
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 please !! Also tried excelApp.Quit(); This is fine, but on viewing "Task List" the application tab shows "Excel.exe" running. And if I run the program again the message
0
1369
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 Excel.Application Dim xlWorkBook As Excel.Workbook Dim strPath As String
1
5567
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 find a way of closing this Hidden occurrence. I can close any foreground instances without any problem, but the same coding does not work for hidden occurences.
3
8373
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 not doing it effectively. If I am debugging my app, and I kill the app before my app exits, but after the call that should close excel, I still have an excell process sitting around. After about 20 + of those stack up, you start to feel it. If I...
5
3039
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 the below API: TargetWorkbook.Save TargetWorkbook.Close
4
4391
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 Integer Dim testCount As Boolean testCount = False For t = 0 To UserListView.Items.Count - 1
10
8162
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 and excel is closed. But there are some commented lines: //xlSeries.XValues = xlWs.get_Range("B2", "B4"); // makes com objects, but which...
1
2757
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 close it myself, I just call ExcelApp.Quit(). Really basic stuff. Only problem is - I need to release all dispatches to detect the Excel process closing, but I need those dispatches (at least the application one) in order to close excel myself. Am...
0
9666
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9511
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10412
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10142
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9986
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
6769
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5551
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3703
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2909
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.