LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5
Default Excel instance won't unload from memory

Ho ho! That seemed to do it, at least in my simple test app. Now let's see
if I can apply it to my main app. Thanks.

The answer to to add GC.Collec();
--
Scott B


"Tom Ogilvy" wrote:

I don't know anything about .NET, but note that at the end of this sample,
they do garbage collection:

http://support.microsoft.com/kb/303872/en-us

Which corresponds to what I recall is a necessary step.

--
Regards,
Tom Ogilvy


"Scott B" wrote:

I've read another post where it says to make sure you don't use unqualified
references like ActiveWorkbooks, and to make sure you set all your references
to null when Quitting Excel. I wrote a very simple C# app (below) where I am
doing these things, but the EXCEL instance can still be seen under Processes
until I close the Windows App.
In my real app, the user can be running a function a number of times, and
each one launches it's own Excel instance, so we end up with a bunch of these
in memory until the main app is closed.
We have an old VB6 app using the Excel 5 library, and it doesn't have this
problem.
Any other pointers?

-----
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace TestWriteExcel2
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}

private void button1_Click(object sender, EventArgs e)
{
Excel.Application oExcel = new Excel.Application();
oExcel.Visible = true;

try
{
Excel.Workbook obWb =
oExcel.Workbooks.Open("c:\\temp\\testWrite.xls",

System.Type.Missing,
false,
System.Type.Missing,
System.Type.Missing,
System.Type.Missing,
false,
System.Type.Missing,
System.Type.Missing,
System.Type.Missing,
System.Type.Missing,
System.Type.Missing,
System.Type.Missing,
System.Type.Missing,
System.Type.Missing);


Excel.Worksheet wks = (Excel.Worksheet)obWb.Worksheets[1];
Excel.Range rng = wks.get_Range("C12", System.Type.Missing);
rng.Value2 = this.textBox1.Text;
rng = null;
wks = null;
//obWb.Save();
obWb.Close(true, System.Type.Missing, System.Type.Missing);
obWb = null;
oExcel.Quit();
oExcel = null;
}
catch (Exception ex)
{

MessageBox.Show("Error opening Excel file.\n" + ex.Message);

}
}
}
}


--
Scott B

 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
How do I remove (not unload) a user installed Excel add-in ? bill h Excel Discussion (Misc queries) 1 March 1st 10 09:16 PM
How to unload Excel Addin Application? cherishman Excel Programming 5 March 21st 05 12:50 PM
Excel Won't Unload... Steven8R Excel Programming 3 October 20th 04 04:42 AM
How to unload a form in excel vba? Edward[_7_] Excel Programming 2 September 30th 04 04:39 PM
Unload from Memory Charles Williams Excel Programming 0 July 18th 03 08:42 AM


All times are GMT +1. The time now is 07:13 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"