1

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 });
Community
  • 1
  • 1
chiccodoro
  • 14,407
  • 19
  • 87
  • 130
  • I'm able to reproduce this, but I have no idea yet for a workaround. – Dirk Vollmar Sep 17 '10 at 15:20
  • @0xA3: What Excel version do *you* have? I've added mine to my question. – chiccodoro Sep 17 '10 at 15:38
  • @chiccodoro. I was not able to reproduce this error. I'm using VS2008 .NET 3.5 SP1, OS is Windows XP SP3, Excel 2007 version is `12.0.6504.5001`. – Garett Sep 17 '10 at 17:36
  • Seems to get nasty... I have to boxes, one Win7 64-bit, one Win7 32-bit, both with Excel 12.0.6535.5002, SP2 MSO 12.0.6535.5002. On the 32-bit OS Excel is crashing, on the 64-bit OS there is no problem. Looks like this is either a configuration problem or related to the OS. However, the Excel window is activated and restored in the functioning case despite `ProcessWindowStyle.Minimized`. – Dirk Vollmar Sep 17 '10 at 18:20
  • Uh oh, seems like a bug in Excel or so. I fear no one will be able to help me out... – chiccodoro Sep 20 '10 at 06:36
  • Have you tried using COM automation with the workaround described here: http://support.microsoft.com/kb/213489 – Dirk Vollmar Sep 20 '10 at 08:51
  • @0xA3, yes I do. It's not feasible if you don't know the add-ins. I tried looping through all the add-ins and unload then load them, but it didn't work. In contrary, it messed up the add-ins so they didn't work properly anymore afterwards... – chiccodoro Sep 20 '10 at 11:32

0 Answers0