
Accessing VBIDE.VBE.VBProjects via Excel in VB .NET Causes Excel To Crash When App Terminates
I'm having a problem which I REALLY need to fix. If anyone could help I would really appreciate it.
The problem arises when accessing the VBProjects object in an Excel application (eg. Application.VBE.VBProjects) from .NET. After you do this, Excel application crashes when it is terminated. I've included sample code to recreate the error.
Create a console project and reference Excel and VBIDE. Add the following code:
Public Sub Main()
'**** Dimension Local Variables ****
Dim XL As New Excel.Application()
Dim VBProject As VBIDE.VBProject
'**** Access VB Projects ****
For Each VBProject In XL.VBE.VBProjects
Next VBProject
'**** Close Excel Application ****
XL.Quit()
XL = Nothing
End Sub
When the application terminates and the garbage collection is called, the Excel application crashes and returns:
OleMainThreadWndName: excel.exe - Application Error
The instruction at "0x77b26033" referenced memory at "0x01144a94". The memory could not be read.
I'm running NT and Excel 98. To work around I'm currently calling a VB6 .dll that performs the required task (stripping VBProjects from an Excel workbook) but that is a less than perfect solution.
Please help.
**********************************************************************
Comprehensive, categorised, searchable collection of links to ASP & ASP.NET resources...