Powerpoint 显示“无法启动应用程序”当 Excel 图表对象嵌入其中时出错

发布于 2024-09-05 01:44:22 字数 1273 浏览 9 评论 0原文

当 Excel 工作表或图表嵌入到 Word 或 Powerpoint 中时,这是一个非常常见的问题。我在 Word 和 Powerpoint 中都看到了这个问题,原因似乎是 Excel 附加的 COM 插件。 COM 插件是用 C# (.NET) 编写的。请参阅附图中的错误对话框。

我调试了插件并发现了一个非常奇怪的行为。 COM 插件中的 OnConnection(...)、OnDisConnection(...) 等方法工作正常,直到我向代码添加事件处理程序。即处理 Worksheet_SheetChange、SelectionChange 或 Excel 中可用的任何类似事件。只要我添加一个事件处理程序(尽管我的代码有多个),Word 和 Powerpoint 就会开始抱怨并且不激活嵌入的对象。

在互联网上的一些帖子中,人们被要求删除 Office 的防病毒插件(在我的情况下没有),所以这让我相信问题与 COM 插件有一定关系,这些插件是在主机应用程序激活时加载的物体。

有谁知道这里发生了什么?PowerPoint 错误

文字错误

更新于 2010 年 6 月 21 日


Found out that both Events and changes to ComAddIns collection creates problems when the embedded object is activated. I have now used the Excel::Application::UserControl property to check whether Excel is in embedded state and then skip any OnConnection(...) and OnDisconnection(...) code.

事件问题的一种解决方案是将所有应用程序级事件移至 VBA 代码并调用到 .NET。从而从 .NET 代码中删除所有事件处理程序。

可能还有更多情况,嵌入式对象可能无法初始化,因此我选择禁用 COM 插件,即完全跳过 OnConnection(...) 和 OnDisconnection(...) 方法中的代码。

This is a very common problem when Excel Worksheet or Chart is embedded into Word or Powerpoint. I am seeing this problem in both Word and Powerpoint and the reason it seems is the COM addin attached to Excel. The COM addin is written in C# (.NET). See the attached images for error dialogs.

I debugged the addin and found a very strange behavior. The OnConnection(...), OnDisConnection(...) etc methods in the COM addin works fine until I add an event handler to the code. i.e. handle the Worksheet_SheetChange, SelectionChange or any similar event available in Excel. As soon as I add even a single event handler (though my code has several), Word and Powerpoint start complaining and do not Activate the embedded object.

On some of the posts on the internet, people have been asked to remove the anti-virus addins for office (none in my case) so this makes me believe that the problem is somewhat related to COM addins which are loaded when the host app activates the object.

Does anyone have any idea of whats happening here?PowerPoint Error

Word Error

UPDATED 21-JUNE-2010


Found out that both Events and changes to ComAddIns collection creates problems when the embedded object is activated. I have now used the Excel::Application::UserControl property to check whether Excel is in embedded state and then skip any OnConnection(...) and OnDisconnection(...) code.

One solution to Events problem can be to move all the application level events to VBA code and call into .NET. Thereby removing all event handlers from .NET code.

There may be even more scenarios where an embedded object might fail to initialize so I choose to disable the COM addin i.e. skip the code in OnConnection(...) and OnDisconnection(...) methods altogether.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

零崎曲识 2024-09-12 01:44:22

以下是我为摆脱这个恼人问题所做的操作:

  1. 删除 .NET 代码中的所有事件处理程序并依赖 VBA 应用程序事件,即而不是处理 Excel::Application::Worksheet_Activate(...) 事件,在 VBA 模块中处理它们,并在收到事件时调用插件。
    .NET 事件处理程序似乎以某种方式破坏了状态。

  2. 使用自定义参数中的标志禁用与 OnConnection(...) 中的插件交互的任何代码。有关该标志的详细信息,请参阅以下链接:
    COM 加载项详细信息

我提到了 Excel ::Application::UserControl 属性,但在某些情况下并不可靠。我们需要考虑以下情况,自定义数组参数 OnConnection(...) 是最可靠的:

  1. Excel 作为独立应用程序启动
  2. Excel 在其他应用程序中作为嵌入式应用程序启动
  3. Excel 通过自动化启动,例如 CreateObject(...)

I当 Excel 处于嵌入模式时,首选完全禁用插件。这取决于您在 OnConnection(...) 中执行的代码以及其他应用程序在执行时如何响应它。必须实施第 1 点来解决此问题。

如果有人对此有更好的解决方案,请告诉我:)

Here is what I did to get rid of this annoying problem:

  1. Remove all event handlers in the .NET code and rely on the VBA Application Events i.e. Instead of handling Excel::Application::Worksheet_Activate(...) event, handle them in a VBA module and call into the addin when an event is received.
    The .NET event handlers seems to corrupt the state somehow.

  2. Disable any code that interacts with the addin in OnConnection(...) using the flag in custom param. See the following link for details on the flag:
    COM AddIns in Detail

I mentioned about the Excel::Application::UserControl property but it is not reliable in some cases. We need to consider the following cases and the custom array param is OnConnection(...) is the most reliable:

  1. Excel started as independent application
  2. Excel started as embedded app in some other application
  3. Excel started through automation e.g. CreateObject(...)

I preferred disabling the addin totally when Excel is in embedded mode. It depends what code you are executing in your OnConnection(...) and how other applications respond to it when executed. Point #1 has to be implemented to solve this issue.

If anybody has a better solution to this, please let me know :)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文