473,503 Members | 3,045 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Excel.exe can't be released from memory

LBT
Good day VB.Net seniors and experts,

I have a window service application which will import data from Excel file.
I face a problem

where Excel.exe process cannot be released from memory once the application
finish process an

Excel file. I did put the code to dereference those Excel objects being
created but seem like

the code is not working. Some portion of my code is shown as follows:

------------------------------------------------------------------------------
Imports System.Runtime.InteropServices.Marshal

Public oExcel As Object
Public oBook2 As Object
Public oSheet As Object

Try
oExcel = CreateObject("Excel.Application")
oBook2 = oExcel.Workbooks.Open(Path, 0)
oExcel.GoTo(Reference:="TCell")
oSheet = oBook2.ActiveSheet

// Grab required data from Excel Sheet

Catch err as Exception
// Log to event log and set "MoveToError" flag as TRUE

Finally
ReleaseComObject(oSheet)
oSheet = Nothing
oBook2.Saved = True
oBook2.Close()
ReleaseComObject(oBook2)
oBook2 = Nothing
oExcel.Quit()
ReleaseComObject(oExcel)
oExcel = Nothing
// Move the Excel file to "Error" folder if "MoveToError" flag is TRUE

End Tr
--------------------------------------------------------------------------------

Any idea why I can't terminate the Excel.exe process? The process is still
shown in Task

Manager.

Thanks a lot

Nov 21 '05 #1
2 1858


"LBT" <LB*@discussions.microsoft.com> schrieb im Newsbeitrag
news:A5**********************************@microsof t.com...
Good day VB.Net seniors and experts,

I have a window service application which will import data from Excel
file.
I face a problem

where Excel.exe process cannot be released from memory once the
application
finish process an

Excel file. I did put the code to dereference those Excel objects being
created but seem like

the code is not working. Some portion of my code is shown as follows:

------------------------------------------------------------------------------
Imports System.Runtime.InteropServices.Marshal

Public oExcel As Object
Public oBook2 As Object
Public oSheet As Object

Try
oExcel = CreateObject("Excel.Application")
oBook2 = oExcel.Workbooks.Open(Path, 0)
oExcel.GoTo(Reference:="TCell")
oSheet = oBook2.ActiveSheet

// Grab required data from Excel Sheet

Catch err as Exception
// Log to event log and set "MoveToError" flag as TRUE

Finally
ReleaseComObject(oSheet)
oSheet = Nothing
oBook2.Saved = True
oBook2.Close()
ReleaseComObject(oBook2)
oBook2 = Nothing
oExcel.Quit()
ReleaseComObject(oExcel)
oExcel = Nothing
// Move the Excel file to "Error" folder if "MoveToError" flag is TRUE

End Try
--------------------------------------------------------------------------------

Any idea why I can't terminate the Excel.exe process? The process is still
shown in Task


PRB: Office Application Does Not Quit After Automation from Visual Studio
..NET Client
<URL:http://support.microsoft.com/?scid=kb;EN-US;317109>
-> "Troubleshooting"

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>

Nov 21 '05 #2
I have noticed a common thread when people say that microsoft's
"solution" does not work. They try to use an "Open" on the the
workbooks object as opposed to an "Add". My code below does not work,
it leaves Excel open in task manager. I suspect there may be an issue
with Open.

Am I just missing something on the oBooks.Open("c:\Data.xls")
statement?

I am accessing the Microsoft Excel 10.0 Object Library, TypeLib Version
1.4 on a Windows XP Pro Version 2002 Service Pack 1 if that helps.
Private Sub NAR(ByVal o As Object)
Try
System.Runtime.InteropServices.Marshal.ReleaseComO bject(o)
Catch
Finally
o = Nothing
End Try
End Sub

Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button3.Click
Dim oApp As New Excel.Application()
Dim oBooks As Excel.Workbooks = oApp.Workbooks
Dim oBook As Excel.Workbook = oBooks.Open("c:\Data.xls")
' the above line is the only difference
' The original line is below
' Dim oBook as Excel.Workbook = oBooks.Add

Dim oSheet As Excel.Worksheet = oApp.ActiveSheet

NAR(oSheet)
oBook.Close(False)
NAR(oBook)
NAR(oBooks)
oApp.Quit()
NAR(oApp)

Debug.WriteLine("Sleeping...")
System.Threading.Thread.Sleep(5000)
Debug.WriteLine("End Excel")
Me.Close()
End Sub

Nov 21 '05 #3

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

Similar topics

4
2187
by: Ariel Gimenez | last post by:
Hi in my app im working with excel using cominterop when fished my work with excel i execute this code oWB.Close(null,null,null); oXL.Workbooks.Close(); oXL.Quit();...
2
12699
by: Sreedhar Vankayala | last post by:
Hi, I joined a project where we need to import data from a excel file into sql server via the asp.net. After doing a long research found that #1. Upload Excel file to the server #2. Load or...
4
3064
by: Rich Wallace | last post by:
Hi all, I have a VB app that runs and manages individual XLS files within a single COM object. Upon processing the final fie, I attempt to close out the EXCEL object and release it using...
5
2648
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...
4
1754
by: Mr.Doubt | last post by:
I've a widows application, that makes use of an EXCEL COM object, to run a few macros available in a EXCEL file. The object is created when the app is started and is closed when the app is closed....
8
38156
by: SteveS | last post by:
I'm attempting to close EXCEL from within my VB.NET application. Using the excel object library to write data to my spreadsheet is working fine but when I try to quit application object it does not...
5
2749
by: RJN | last post by:
Hi I'm invoking the excel object from ASP.Net application. My development machine is Windows 2000 and MS Office is installed on my m/c. I have added reference to the Excel COM object, I have...
2
2508
by: ChrisFrohlich | last post by:
I have been trying to use the Office PIA's to write an ASP.NEt page to: 1. Open a template workbook 2. Populate some data 3. Save the file back to the server 4. Quit Excel and free up Memory I...
1
1366
by: Scott M. | last post by:
Many methods return objects when they are called. With Excel these objects are placed in memory and must be destroyed via ReleaseComObject as you have done with your NAR method, but the line: ...
0
7193
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,...
0
7316
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...
1
6975
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...
0
5562
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 project—planning, coding, testing,...
1
4992
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...
0
4666
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...
0
3160
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
1
728
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
371
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...

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.