473,811 Members | 3,182 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Ending An Excel Process

24 New Member
When I create an instance of an Excel Application class and then quit the app and release the object (like below) the EXCEL process is still running in the the task manager. I have built an algorithm to find the process id and kill the process through that but I shouldn't have to. Is there a cleaner solution?
Expand|Select|Wrap|Line Numbers
  1.  
  2.  
  3.         xlApp = New Excel.ApplicationClass
  4.         'do stuff with excel app class instance
  5.  
  6.         xlApp.Quit()
  7.         releaseObject(xlApp)
  8.  
  9.  
  10.     Private Sub releaseObject(ByVal obj As Object)
  11.         Try
  12.             System.Runtime.InteropServices.Marshal.ReleaseComObject(obj)
  13.             obj = Nothing
  14.         Catch ex As Exception
  15.             obj = Nothing
  16.         Finally
  17.             GC.Collect()
  18.         End Try
  19.     End Sub
  20.  
  21.  
  22.  
  23.  
  24.  
  25.  
Jun 3 '11 #1
2 3449
R MacDonald
24 New Member
I think that you are experiencing an "implicit reference" problem. If you don't assign an object created by an Office application (such as Excel) to an explicit variable, then an implicit variable is created for that object. This implicit variable continues to exist until the application itself is closed.

To solve this problem, search through the code in the section "'do stuff with excel app class instance" for all Excel properties and methods that return an object. Ensure that these objects are assigned to an explicit variable. You don't actually need to do anything with these variables. You can either set them to Nothing after you are finished with them, or just let them be garbage collected.

Cheers,
Randy
Jun 3 '11 #2
Stewart Ross
2,545 Recognized Expert Moderator Specialist
If you have modified a workbook when you issue a Quit command Excel will wait for the user to confirm whether or not to save the current workbook. If you are running Excel in non-visible mode it will simply hang, as it cannot be seen by the user at the time, and you will indeed end up with an instance of Excel in task manager.

You can resolve this by setting the DisplayAlerts property false before quitting:

Expand|Select|Wrap|Line Numbers
  1. xlApp.DisplayAlerts = False
-Stewart
Jun 3 '11 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

11
2250
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 returns to the Web form to display. All is OK, except EXCEL remains in the process list in task manager. I am following all guideline in releasing the com components.
2
5439
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 recommended by many for web applications. I create the instances of Excel, Workbook and the worksheet. And later on Release the references by “System.Runtime.InteropServices.Marshal.ReleaseComObject(Object)” and making the object as null finally....
2
21960
by: Powerguy | last post by:
Hi all, I am looking for a way to get the Process id (or a handle) of an EXCEL process created from within my code. For example when the following code is executed: Dim EXL As Excel.Application = New Excel.Application a new instance of EXCEL.EXE is created in the task manager.
18
3100
by: lgbjr | last post by:
Hi All, I have a VB.NET app that, among other things, writes data to Excel. I am having trouble getting the Excel process to terminate after I quit Excel. I found an article related to this problem: http://support.microsoft.com/default.aspx?scid=kb;en-us;317109 Below is a sample of code that I wrote based on the above article. The excel workbook, worksheets, and all of the cells are properly formatted when Excel
16
4556
by: LP | last post by:
Hello, I am trying to use .NET with Excel. I installed Office 2003 and selected ..NET programming suport option, so it installed all those PIA, as MS sugests. But I can not find a way to destroy Excel process, it still hangs in the taks manager' Processes as running. I am trying very simple code (see below), but Excel wont go away, I tried just about anything I could find on MSDN or by Google. Even calling WIN32 API to destroy Excel. But...
1
1672
by: Tony Hedge | last post by:
Hello, In my .NET code behind, I open up an excel file, and process all the rows in the worksheet that I'm interested in. Problem is when I'm done and issue the quit method. The EXCEL process still exists in task manager (owner is ASPNET). Here is the code: Dim xcl As New Excel.Application Dim wbk As Excel.Workbook Dim xs As Excel.Worksheet
13
3016
by: chuckie_9497 | last post by:
hello all you gurus. I am struggling with releasing com objects. I have isolated the problem to the code below. Objects are released and the process ends until I use "int k = sheet.Count;" Then the process does not end. So I feel confident the problem occurrs here. It appears another reference is created that needs to be closed. Can anyone tell me how to do this? :) Thank you Excel.Workbook workbook =
0
9726
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, well explore What is ONU, What Is Router, ONU & Routers main usage, and What is the difference between ONU and Router. Lets take a closer look ! Part I. Meaning of...
0
9605
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
10647
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...
0
10384
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10395
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
9204
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 projectplanning, coding, testing, and deploymentwithout human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7667
isladogs
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 presenter, Adolph Dupr who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6887
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();...
2
3865
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.