Accessing VBIDE.VBE.VBProjects via Excel in VB .NET Causes Excel To Crash When Closed 
Author Message
 Accessing VBIDE.VBE.VBProjects via Excel in VB .NET Causes Excel To Crash When Closed

Here is an interesting one. 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.

Any ideas anyone?



Sat, 30 Jul 2005 12:50:58 GMT  
 Accessing VBIDE.VBE.VBProjects via Excel in VB .NET Causes Excel To Crash When Closed
Paul, enumerate through the sheets collectionand set the objects to nothing.

You'll get the same error in VB6.


Quote:
> Here is an interesting one. 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.

> Any ideas anyone?



Sat, 30 Jul 2005 14:00:56 GMT  
 Accessing VBIDE.VBE.VBProjects via Excel in VB .NET Causes Excel To Crash When Closed

Richard,

Is that a solution or an observation? If it's a solution I don't
understand. Can you elaborate?

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!



Sat, 30 Jul 2005 14:11:55 GMT  
 Accessing VBIDE.VBE.VBProjects via Excel in VB .NET Causes Excel To Crash When Closed
Paul:

Like many of the office object models, the parent object -- in this case,
the Excel.Application -- when called, brings up Excel and automates the
process of starting the application with a default workspace, book and
sheets.

Because of this, simply closing down Excel doesn't assure proper closure of
these objects. That's why I suggested you close these objects out before
setting the excel.application to nothing.


Quote:

> Richard,

> Is that a solution or an observation? If it's a solution I don't
> understand. Can you elaborate?

> *** Sent via Developersdex http://www.developersdex.com ***
> Don't just participate in USENET...get rewarded for it!



Sat, 30 Jul 2005 20:56:59 GMT  
 Accessing VBIDE.VBE.VBProjects via Excel in VB .NET Causes Excel To Crash When Closed
Richard,

When you instance an Excel application via OLE:

   Dim XL As New Excel.Application

The application is created blank with no worksheets, workbooks or
add-ins. I believe MS did this to speed up the OLE creation of
application objects.

The code example I posted creates an application with nothing open
(including no VBProject objects).

If the following two lines are removed it works perfectly.

     '**** Access VB Projects ****
     For Each VBProject In XL.VBE.VBProjects
     Next VBProject

It also works even if you access the VBProjects.Count property. But as
soon as the VBProjects is enumerated it causes problems.

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!



Sun, 31 Jul 2005 10:12:07 GMT  
 Accessing VBIDE.VBE.VBProjects via Excel in VB .NET Causes Excel To Crash When Closed
Paul:

Thanks for helping me out.


Quote:
> Richard,

> When you instance an Excel application via OLE:

>    Dim XL As New Excel.Application

> The application is created blank with no worksheets, workbooks or
> add-ins. I believe MS did this to speed up the OLE creation of
> application objects.

> The code example I posted creates an application with nothing open
> (including no VBProject objects).

> If the following two lines are removed it works perfectly.

>      '**** Access VB Projects ****
>      For Each VBProject In XL.VBE.VBProjects
>      Next VBProject

> It also works even if you access the VBProjects.Count property. But as
> soon as the VBProjects is enumerated it causes problems.

> *** Sent via Developersdex http://www.developersdex.com ***
> Don't just participate in USENET...get rewarded for it!



Tue, 02 Aug 2005 13:32:49 GMT  
 
 [ 6 post ] 

 Relevant Pages 

1. Accessing VBIDE.VBE.VBProjects via Excel in VB .NET Causes Excel To Crash When App Terminates

2. Accessing VBIDE.VBE.VBProjects via Excel in VB .NET Causes Excel To Crash When App Terminates

3. Compatibility Problem Using MS Excel 97 VBA on Excel 2000/XP - Causes crashes

4. Help > Crash saving Excel through VB.Net

5. VB6 - Excel Export compiled under XP causes crash under W98

6. Problem with Excel's VBA: SQLOpen and SQLClose Cause Crash

7. Using excel via VB .NET

8. Help with writing Datagrid Contents back to EXCEL via VB.NET

9. Pasting Range from Excel 2002 via VBA to Word causes a New Workbook to open

10. VBE for excel as a Dev Tols (like VB in Visual Studio)

11. VBIDE and VBPROJECTS objects problem

12. Excel 2000 crashes when running macros created in Excel 97

 

 
Powered by phpBB® Forum Software