Home |
Search |
Today's Posts |
#1
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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 |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
How do I remove (not unload) a user installed Excel add-in ? | Excel Discussion (Misc queries) | |||
How to unload Excel Addin Application? | Excel Programming | |||
Excel Won't Unload... | Excel Programming | |||
How to unload a form in excel vba? | Excel Programming | |||
Unload from Memory | Excel Programming |