473,320 Members | 1,802 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,320 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 3047
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: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.