加载项使 Excel 在最小化启动时崩溃
我使用 Process.Start(...)
从 C# WinForms 应用程序中启动 Excel(这是有原因的)。我想在后台启动它,而不分散用户的注意力,所以我尝试将其最小化或隐藏启动。在这两种情况下,我都遇到了非常奇怪的行为:
几秒钟后,Excel 恢复窗口(如果隐藏,甚至使其可见),然后崩溃,并显示:“Microsoft Office Excel 遇到问题,需要(Win XP 崩溃消息。)”
如果我通过双击桌面上的快捷方式图标手动启动 Excel,然后立即切换到另一个应用程序窗口,也会发生同样的情况,导致 Excel 窗口失去焦点。启动期间。
仅当任何 XLA 加载项包含用户窗体时,才会出现此问题。如果我删除用户窗体,问题就会消失。如果我删除该加载项,问题就会消失。
任何帮助都值得赞赏,只要它
- 解释为什么会发生这种
- 情况 我可以在加载项中更改一些内容
- 解决此错误的方法(不使用 COM)
- 不是使用 COM 的建议。 (请参阅此处了解我为什么不这样做。)
- 不 更新 Excel 的建议(我不能)
重现步骤:
- 使用空工作簿启动 Excel 2007。
- 另存为...
- 文件类型:Excel 2003 加载项 (*.xla)
- 位置:%APPDATA%\Microsoft\Excel\XLSTART\foobar.xla
- Alt + F11(打开 VBA 编辑器)
- 将用户窗体添加到项目中。
保存并退出 Excel
启动 Excel,然后立即单击 Firefox 或任务栏中的任何选项卡以激活除 Excel 之外的任何窗口。
- 等待并观察 Excel 启动,直到崩溃。
重新启动 Excel 后,它显示:
<块引用>Excel 在使用“foobar”加载项时遇到了严重问题。如果您多次看到此消息,则应禁用此加载项并检查是否有可用更新。您想禁用此加载项吗?
详细信息/发现:
- Excel 版本:12.0.6535.5002,SP2 MSO 12.0.6425.1000
- 0xA3 在他的评论中报告,他可以使用 Excel 12.0.6535.5002,SP2 MSO 12.0.6535.5002 在 32 位计算机上重现它,
- 我尝试过使用 2007 年的插件(XLAM)。同样的问题,只是如果它不包含任何用户窗体,它甚至会崩溃。
- 0xA3 报告在他的 64 位计算机上它可以工作,但是 Excel 仍然意外弹出(但不会崩溃)。到目前为止,我的测试人员的两台机器也是如此。
这是我想在 C# 中使用的代码(请注意,该问题可以完全独立于任何 C# 应用程序重现,请参见上文)。
Process.Start(new ProcessStartInfo("excel.exe")
{ WindowStyle = ProcessWindowStyle.Minimized });
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 });
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论