Add-in makes Excel crash when starting minimized

1.4k Views Asked by At

I start Excel from within my C# WinForms application using Process.Start(...) (this has a reason). I want to start it in background, without distracting the user, so I try to start it minimized or hidden. In both cases, I experience a very weird behavior:

After some seconds, Excel restores the window (even makes it visible if it's hidden) and then crashes saying: "Microsoft Office Excel has encountered a problem and needs to close. (Win XP crash message.)"

The same thing happens if I start Excel manually by double-clicking its Shortcut Icon on the Desktop and then just switch to another application window immediately, such that the Excel window loses focus during startup.

The problem appears only if any of the XLA add-in contains a UserForm. If I remove the UserForm, the problem disappears. If I remove the add-in, the problem disappears.

Any help is appreciated, as long as it is

  • An explanation of why this happens
  • Something I can change in the add-in
  • A way how to work around this bug (without using COM)
  • Not a suggestion to use COM. (See here to understand why I don't.)
  • Not an advice to update Excel (I can't)

Steps to reproduce:

  • Start Excel 2007 with an empty workbook.
  • Save As...
    • File Type: Excel 2003 Add-in (*.xla)
    • Location: %APPDATA%\Microsoft\Excel\XLSTART\foobar.xla
  • Alt + F11 (open VBA editor)
  • Add a UserForm to the project.
  • Save and Quit Excel

  • Start Excel and then immediately click on the Firefox or whatever tab in the taskbar to activate any window other than Excel.

  • Wait and watch Excel start, until it crashes.
  • After restarting Excel it says:

    Excel experienced a serious problem with the 'foobar' add-in. If you have seen this message multiple times, you should disable this add-in and check to see if an update is available. Do you want to disable this add-in?


Details/Findings:

  • Excel version: 12.0.6535.5002, SP2 MSO 12.0.6425.1000
  • 0xA3 reported in his comment he could reproduce it on 32 bit machine with Excel 12.0.6535.5002, SP2 MSO 12.0.6535.5002
  • I've tried with a 2007 add-in (XLAM). The same problem, except that it even crashes if it doesn't contain any UserForms.
  • 0xA3 reported that on his 64 bit machine it worked, however Excel still pops up unexpectedly (but doesn't crash). The same holds for 2 machines of my testers so far.

This is the code I wanted to use in C# (note that the problem can be reproduced completely independent of any C# app, see above).

Process.Start(new ProcessStartInfo("excel.exe") 
    { WindowStyle = ProcessWindowStyle.Minimized });
0

There are 0 best solutions below