473,386 Members | 1,609 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Application error when releaseing Excel COM object

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
System.Runtime.InteropServices.Marshal.ReleaseComO bject.

I have a Try...Catch in my routine as seen below and when I receive the
error, my Catch is never called so my app sees the release as successful,
but when I look in Task Manager, the EXCEL.EXE instance is still running and
a Windows Application error pops up...see below code snippet

Private Sub ObjectRelease(ByVal o As Object)
Try
System.Runtime.InteropServices.Marshal.ReleaseComO bject(o)
Catch
MsgBox(Err.Description)
Finally
o = Nothing
End Try
End Sub

Error:
Microsoft Excel: EXCEL.EXE - Application Error
The instruction as "0x77ab193d" referenced memory at "0x0207da34". The
memory could not be "read".

Memory should not be an issue on the server I am running the app on. BTW, I
do clean up any/all references to any Sheets, Workbooks/Workbook objects
prior to calling the ablove code:

'Release the Excel objects
oBook.Save()
ObjectRelease(oSheet)
oBook.Close(False)
ObjectRelease(oBook)
ObjectRelease(oBooks)
oExcel.Quit()

Any ideas??

TIA
-Rich
Nov 20 '05 #1
4 3053
Hi,

Try passing o byref instead of byval.

Ken
---------------
"Rich Wallace" <ri**********@minusthecannedmeat.jfsheadotcom> wrote in
message news:uu**************@TK2MSFTNGP09.phx.gbl...
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
System.Runtime.InteropServices.Marshal.ReleaseComO bject.

I have a Try...Catch in my routine as seen below and when I receive the
error, my Catch is never called so my app sees the release as successful,
but when I look in Task Manager, the EXCEL.EXE instance is still running and a Windows Application error pops up...see below code snippet

Private Sub ObjectRelease(ByVal o As Object)
Try
System.Runtime.InteropServices.Marshal.ReleaseComO bject(o)
Catch
MsgBox(Err.Description)
Finally
o = Nothing
End Try
End Sub

Error:
Microsoft Excel: EXCEL.EXE - Application Error
The instruction as "0x77ab193d" referenced memory at "0x0207da34". The
memory could not be "read".

Memory should not be an issue on the server I am running the app on. BTW, I do clean up any/all references to any Sheets, Workbooks/Workbook objects
prior to calling the ablove code:

'Release the Excel objects
oBook.Save()
ObjectRelease(oSheet)
oBook.Close(False)
ObjectRelease(oBook)
ObjectRelease(oBooks)
oExcel.Quit()

Any ideas??

TIA
-Rich

Nov 20 '05 #2
Thanks Ken,

Same result.

"Ken Tucker [MVP]" <vb***@bellsouth.net> wrote in message
news:%2****************@TK2MSFTNGP10.phx.gbl...
Hi,

Try passing o byref instead of byval.

Ken
---------------
"Rich Wallace" <ri**********@minusthecannedmeat.jfsheadotcom> wrote in
message news:uu**************@TK2MSFTNGP09.phx.gbl...
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
System.Runtime.InteropServices.Marshal.ReleaseComO bject.

I have a Try...Catch in my routine as seen below and when I receive the
error, my Catch is never called so my app sees the release as successful, but when I look in Task Manager, the EXCEL.EXE instance is still running

and
a Windows Application error pops up...see below code snippet

Private Sub ObjectRelease(ByVal o As Object)
Try
System.Runtime.InteropServices.Marshal.ReleaseComO bject(o)
Catch
MsgBox(Err.Description)
Finally
o = Nothing
End Try
End Sub

Error:
Microsoft Excel: EXCEL.EXE - Application Error
The instruction as "0x77ab193d" referenced memory at "0x0207da34". The
memory could not be "read".

Memory should not be an issue on the server I am running the app on.

BTW, I
do clean up any/all references to any Sheets, Workbooks/Workbook objects
prior to calling the ablove code:

'Release the Excel objects
oBook.Save()
ObjectRelease(oSheet)
oBook.Close(False)
ObjectRelease(oBook)
ObjectRelease(oBooks)
oExcel.Quit()

Any ideas??

TIA
-Rich


Nov 20 '05 #3
Rich,
The following statement requires ByRef as Ken suggests.
o = Nothing System.Runtime.InteropServices.Marshal.ReleaseComO bject(o) Should be called in a loop until it reaches zero to ensure all .NET
references are released, see the help for ReleaseComObject for details.

Also be very certain you release the COM objects in the correct order (it
appears that you are). And you release all your COM objects.

Where are you seeing the following error? Error:
Microsoft Excel: EXCEL.EXE - Application Error
The instruction as "0x77ab193d" referenced memory at "0x0207da34". The
memory could not be "read".
Hope this helps
Jay

"Rich Wallace" <ri**********@minusthecannedmeat.jfsheadotcom> wrote in
message news:uu**************@TK2MSFTNGP09.phx.gbl... 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
System.Runtime.InteropServices.Marshal.ReleaseComO bject.

I have a Try...Catch in my routine as seen below and when I receive the
error, my Catch is never called so my app sees the release as successful,
but when I look in Task Manager, the EXCEL.EXE instance is still running and a Windows Application error pops up...see below code snippet

Private Sub ObjectRelease(ByVal o As Object)
Try
System.Runtime.InteropServices.Marshal.ReleaseComO bject(o)
Catch
MsgBox(Err.Description)
Finally
o = Nothing
End Try
End Sub

Error:
Microsoft Excel: EXCEL.EXE - Application Error
The instruction as "0x77ab193d" referenced memory at "0x0207da34". The
memory could not be "read".

Memory should not be an issue on the server I am running the app on. BTW, I do clean up any/all references to any Sheets, Workbooks/Workbook objects
prior to calling the ablove code:

'Release the Excel objects
oBook.Save()
ObjectRelease(oSheet)
oBook.Close(False)
ObjectRelease(oBook)
ObjectRelease(oBooks)
oExcel.Quit()

Any ideas??

TIA
-Rich

Nov 20 '05 #4
Hi,

Sample on how I open and release excel

Dim oXL As Excel.Application

Dim oWB As Excel.Workbook

Dim oSheet As Excel.Worksheet

Dim oRng As Excel.Range

' Start Excel and get Application object.

oXL = CreateObject("Excel.Application")

oXL.Visible = True

' Get a new workbook.

oWB = oXL.Workbooks.Add

oSheet = oWB.ActiveSheet

' Add table headers going cell by cell.

oSheet.Cells(1, 1).Value = "First Name"

oSheet.Cells(1, 2).Value = "Last Name"

oSheet.Cells(1, 3).Value = "Full Name"

oSheet.Cells(1, 4).Value = "Salary"

' Format A1:D1 as bold, vertical alignment = center.

With oSheet.Range("A1", "D1")

..Font.Bold = True

..VerticalAlignment = Excel.XlVAlign.xlVAlignCenter

End With

' Create an array to set multiple values at once.

Dim saNames(5, 2) As String

saNames(0, 0) = "John"

saNames(0, 1) = "Smith"

saNames(1, 0) = "Tom"

saNames(1, 1) = "Brown"

saNames(2, 0) = "Sue"

saNames(2, 1) = "Thomas"

saNames(3, 0) = "Jane"

saNames(3, 1) = "Jones"

saNames(4, 0) = "Adam"

saNames(4, 1) = "Johnson"

' Fill A2:B6 with an array of values (First and Last Names).

oSheet.Range("A2", "B6").Value = saNames

' Fill C2:C6 with a relative formula (=A2 & " " & B2).

oRng = oSheet.Range("C2", "C6")

oRng.Formula = "=A2 & "" "" & B2"

' Fill D2:D6 with a formula(=RAND()*100000) and apply format.

oRng = oSheet.Range("D2", "D6")

oRng.Formula = "=RAND()*100000"

oRng.NumberFormat = "$0.00"

' AutoFit columns A:D.

oRng = oSheet.Range("A1", "D1")

oRng.EntireColumn.AutoFit()

' Manipulate a variable number of columns for Quarterly Sales Data.

' Make sure Excel is visible and give the user control

' of Excel's lifetime.

oXL.Visible = True

oXL.UserControl = True

' Make sure that you release object references.

oRng = Nothing

oXL.DisplayAlerts = False

oSheet.SaveAs("C:\Test.xls",
FileFormat:=Excel.XlFileFormat.xlXMLSpreadsheet)

oSheet = Nothing

oWB = Nothing

oXL.Quit()

Marshal.ReleaseComObject(oXL)

oXL = Nothing

GC.Collect()

Ken

----------------------

"Rich Wallace" <ri**********@minusthecannedmeat.jfsheadotcom> wrote in
message news:u8**************@TK2MSFTNGP11.phx.gbl...
Thanks Ken,

Same result.

"Ken Tucker [MVP]" <vb***@bellsouth.net> wrote in message
news:%2****************@TK2MSFTNGP10.phx.gbl...
Hi,

Try passing o byref instead of byval.

Ken
---------------
"Rich Wallace" <ri**********@minusthecannedmeat.jfsheadotcom> wrote in
message news:uu**************@TK2MSFTNGP09.phx.gbl...
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
System.Runtime.InteropServices.Marshal.ReleaseComO bject.

I have a Try...Catch in my routine as seen below and when I receive the error, my Catch is never called so my app sees the release as successful, but when I look in Task Manager, the EXCEL.EXE instance is still running
and
a Windows Application error pops up...see below code snippet

Private Sub ObjectRelease(ByVal o As Object)
Try
System.Runtime.InteropServices.Marshal.ReleaseComO bject(o)
Catch
MsgBox(Err.Description)
Finally
o = Nothing
End Try
End Sub

Error:
Microsoft Excel: EXCEL.EXE - Application Error
The instruction as "0x77ab193d" referenced memory at "0x0207da34".

The memory could not be "read".

Memory should not be an issue on the server I am running the app on.

BTW,
I
do clean up any/all references to any Sheets, Workbooks/Workbook objects prior to calling the ablove code:

'Release the Excel objects
oBook.Save()
ObjectRelease(oSheet)
oBook.Close(False)
ObjectRelease(oBook)
ObjectRelease(oBooks)
oExcel.Quit()

Any ideas??

TIA
-Rich



Nov 20 '05 #5

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

Similar topics

2
by: Sri | last post by:
I am writing an asp.net applicaition using VB coding. In a function, I am opening an excel file with the following code, Dim objExcel As Object Dim objWorkBook As Object objExcel =...
4
by: msnnews.msn.com | last post by:
hi there, i've got a form that populates a datagrid, and a button that calls a function to export to an excel file. All is well with the export, no errors are returned, but the Excel instance...
6
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
by: Jason | last post by:
I am having some trouble manipulating Excel files. Currently I am trying to create and then close an Excel file/application with the following code. It works fine, except it leaves an EXCEL...
9
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...
9
NeoPa
by: NeoPa | last post by:
In VBA (I expect VB would be similar) controlling another Office Application (Automation) can be done using the following steps : Ensure the Reference (VBA Window / Tools / References) has been...
4
by: Steve Kershaw | last post by:
Hi, I have a simple web page that starts Excel and fills it with some dummy data. Using IE I can run this web page from the C: drive (IE: "C: \startexcel.htm") and it runs fine. However, when I...
22
by: robertgregson | last post by:
Using C#, .NET3.5, Visual Studio 2008 and WCF on Windows VISTA SP1, I have written a service, service host (as a C# console application) and a client. The service uses...
1
by: raul15791 | last post by:
Hi, I'm new to C#. I'm writing a program that open a new excel file, write into it and lastly close the file. But the program is that there will be a orphaned process named EXCEL.EXE left on the...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
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...

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.