473,671 Members | 2,382 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Excel.EXE won't GO away

I've been using excel within VB.NET applications and I can't get it to close down and remove itself from memory.

I'm using Visual Studio 2003 ver 7.1.3088, Framework 1.1, MS Office 2003 with MS VS Tools for MS Office System 69586-3

After closing all workbooks etc and setting them to nothing, I run the following code to get rid of the Excel Application object

If Not (xlApp Is Nothing) Then
xlApp.Quit()
xlApp = Nothing
GC.Collect()
End If

This does set the application object to nothing in the locals panel but the Excel.EXE process is still running in the Task Manager.

Thanks for your help.
Nov 22 '05 #1
2 3324
Bob
Duncan Allen <Duncan Al***@discussio ns.microsoft.co m> wrote in message news:<C6******* *************** ************@mi crosoft.com>...
I've been using excel within VB.NET applications and I can't get it to close down and remove itself from memory.


I ran into this in c#. I found a ms web page with a great example on
this but can't find it again now.

You are probably creating some objects implicitly by doing something
like xlApp.Workbook. Worksheet and these objects are not getting freed.
Here are some tips :

1) Create all excel ojbects explicitly
2) Quit Excel
3) Use Marshal.Release ComObject on all excel objects
4) Set all excel objects to null

The instance of Excel your code creates should then terminate as you
expect it to.

I hope that helps.

Bob

Here is some sample (c# code)

using System;
using System.Data;
using System.Data.Ole Db;
using System.Drawing;
using System.Drawing. Imaging;
using System.Collecti ons;
using System.Componen tModel;
using System.Windows. Forms;
using System.Reflecti on;
using System.IO;
using System.Runtime. InteropServices ;

private void Export(string saveToName)
{

//Create all Excel objects
Excel.Applicati on oXL;
Excel.Workbook oWB;
Excel.Worksheet oSheet;
Excel.Range oRng;

try
{
//Start Excel and get Application object.
oXL = new Excel.Applicati on();
oXL.DisplayAler ts = false;
oXL.ScreenUpdat ing = false;

//Make sure Excel is hidden
oXL.Visible = false;
oXL.UserControl = false;

//Open the workbook.
oWB = oXL.Workbooks.O pen(excelFileNa me,
Type.Missing,
Type.Missing,
Type.Missing,
Type.Missing,
Type.Missing,
Type.Missing,
Type.Missing,
Type.Missing,
Type.Missing,
Type.Missing,
Type.Missing,
Type.Missing);

oSheet = (Excel.Workshee t) oWB.Worksheets. get_Item(1);

oSheet.Activate ();

//Copy data from data reader to excel
string[] cell = new
string[30]{"A","B","C","D ","E","F","G"," H","I","J","K", "L","M","N","O" ,"P","Q","R","S ","T","U","V"," W","X","Y","Z", "AA","AB","AC", "AD"};

int row = 2;

while (dReader.Read() )
{
for (int index = 0; index < 30; index++)
{ {
oRng = oSheet.get_Rang e(cell[index] + row.ToString(),
cell[index] + row.ToString()) ;

if (dReader[index].ToString() == "")
{
oRng.Value2 = "0";
}
else
{
oRng.Value2 = dReader[index].ToString();
}

//Release the range object
Marshal.Release ComObject(oRng) ;
}

row++;
}

//Save the file
object fileName = saveToName;

oWB.SaveAs(file Name,
Excel.XlFileFor mat.xlExcel9795 ,
Type.Missing,
Type.Missing,
Type.Missing,
Type.Missing,
Excel.XlSaveAsA ccessMode.xlNoC hange,
Type.Missing,
Type.Missing,
Type.Missing,
Type.Missing);

oXL.Quit();
//Free the remaining excel resources
Marshal.Release ComObject(oRng) ;
Marshal.Release ComObject(oShee t);
Marshal.Release ComObject(oWB);
Marshal.Release ComObject(oXL);

oXL = null;
oWB = null;
oSheet = null;
oRng = null;
}
catch( Exception theException )
{
String errorMessage = "Error: ";
errorMessage = String.Concat(e rrorMessage, theException.Me ssage);
errorMessage = String.Concat(e rrorMessage, " Line: ");
errorMessage = String.Concat(e rrorMessage, theException.So urce);

MessageBox.Show (errorMessage, "Error");
}
}
Nov 22 '05 #2
On Fri, 11 Jun 2004 03:51:01 -0700, Duncan Allen <Duncan Al***@discussio ns.microsoft.co m> wrote:

¤ I've been using excel within VB.NET applications and I can't get it to close down and remove itself from memory.
¤
¤ I'm using Visual Studio 2003 ver 7.1.3088, Framework 1.1, MS Office 2003 with MS VS Tools for MS Office System 69586-3
¤
¤ After closing all workbooks etc and setting them to nothing, I run the following code to get rid of the Excel Application object
¤
¤ If Not (xlApp Is Nothing) Then
¤ xlApp.Quit()
¤ xlApp = Nothing
¤ GC.Collect()
¤ End If
¤
¤ This does set the application object to nothing in the locals panel but the Excel.EXE process is still running in the Task Manager.

See if the following helps:

PRB: Office Application Does Not Quit After Automation from Visual Studio .NET Client
http://support.microsoft.com/default...b;EN-US;317109
Paul ~~~ pc******@amerit ech.net
Microsoft MVP (Visual Basic)
Nov 22 '05 #3

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

Similar topics

2
767
by: Duncan Allen | last post by:
I've been using excel within VB.NET applications and I can't get it to close down and remove itself from memory. I'm using Visual Studio 2003 ver 7.1.3088, Framework 1.1, MS Office 2003 with MS VS Tools for MS Office System 69586-3 After closing all workbooks etc and setting them to nothing, I run the following code to get rid of the Excel Application object If Not (xlApp Is Nothing) Then xlApp.Quit() xlApp = Nothing GC.Collect()
11
4044
by: Mr. Smith | last post by:
Hello all, My code can successfully open, write to, format and save several worksheets in a workbook then save it by a given name, close and quit excel. My problem is that if I try and do it again, Excel hangs. OR if I open Excel again (say from a desktop icon) before I close Access, Excel hangs. (this has happened for both 97 & 2000 for me) I of course thought that I mustn't be unloading a variable properly.
3
2995
by: user_5701 | last post by:
Hello, I have an Access 2000 database that I need to export certain queries to Excel 2000. The problem is that I have to take the toolbars away from the users for security purposes, but still let the users have the ability to export to Excel using forms and buttons, using vba code I write. I have attempted using the DoCmd.TransferSpreadsheet option, but it does not look formatted the way the "Analyze It with MS Excel" button does. To...
4
3244
by: Lisa | last post by:
Hi - I'm able to open excel workbooks and word documents, but I can't seem to copy excel charts, named ranges, etc. to a word document. Anyone know of good reference material in this area? What little documentation I've been able to find focuses on using only one office app at a time. Thanks for your help
5
2664
by: Tim Frawley | last post by:
I created a .NET Com Class object for use in ASP reports to export database results directly to Excel. I have it all working just find but I cannot get the Excel process to go away after the job is done. I am using the following .NET code in my Com Class object: <ComClass(DIF2XLS.ClassId, DIF2XLS.InterfaceId, DIF2XLS.EventsId)> _ Public Class DIF2XLS #Region "COM GUIDs"
16
2691
by: alexia.bee | last post by:
Hi all, In some weird reason, excel instance won;t die if i remove the comment from 4 lines of setting values into struct. here is a snipcode public System.Collections.Generic.List<frmMain.sDBTest> LoadTestSet(string TestSetFile, System.Collections.Generic.List<frmMain.sDBTestDBviewList)
9
4541
by: Doug Glancy | last post by:
I got the following code from Francesco Balena's site, for disposing of Com objects: Sub SetNothing(Of T)(ByRef obj As T) ' Dispose of the object if possible If obj IsNot Nothing AndAlso TypeOf obj Is IDisposable Then DirectCast(obj, IDisposable).Dispose()
2
4920
by: Nicholas Dreyer | last post by:
The following error Run-time exception thrown : System.Runtime.InteropServices.COMException - Error loading type library/DLL. happens while running the code listed at the bottom of this message in the environment shown here: Operating System: Microsoft Windows Version 5.1 (Build
4
1783
by: John Brock | last post by:
I have a .NET application that, among other things, creates Excel workbooks, and I have run into a very strange problem involving formulas on one worksheet that reference values on another worksheet. The text I write into, let's say, cell A25 on Sheet1 (using .NET) looks something like this: =VLOOKUP(RC,'Sheet2'!A:X,6,FALSE) On the completed workbook this turns into:
2
2504
by: AlenaMezh | last post by:
Hello! My Code destroys Excel's normal work.After running this code I acan' open excel file as normal. Do you know why? Please, answer. Public Function import_test_1() Dim objXL As Object Dim objWB As Object 'Dim objXL As Excel.Application 'Dim objWB As Excel.Workbook
0
8481
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
8400
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
8924
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
8823
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
8602
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
8672
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...
1
6234
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
5702
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
1814
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.