同时使用 VBA 和 ActiveX 插件时出现 Excel 错误 406。

发布于 2024-12-21 06:48:15 字数 1456 浏览 1 评论 0原文

我的 Excel 插件(XLL AddIn,称之为 MyAddIn)是用 C#、ExcelDNA、NetOffice、VS2010 构建的。客户端有另一个插件(我们称之为B),我猜它是用VBA编写的。 客户说 B 在没有 MyAddIn 的情况下工作正常。安装 MyAddIn 后,B 失败并出现错误:

错误代码:406 错误消息:无法通过 ActiveX DLL、ActiveX 控件或属性页在此主机应用程序中显示非模式表单。

我确实看到了此 Microsoft 资源,但我不想只是告诉客户B 插件需要更改。我想做点什么来避免这种情况发生。

以下是报告的查看该问题的步骤:

  1. 安装 B 插件后,它不会为 Microsoft Excel 创建任何注册表项。
  2. 安装MyAddin 后,它会为Microsoft Excel 创建一个注册表项。
  3. 这里的注册表项基本上告诉我们,启动 Excel 时应该打开该插件,因此 B 插件不会启动,Excel 工作正常,MyAddIn 工作正常。
  4. 现在,当 B 插件启动时,它会给出上面所示的 406 错误。
  5. 我们可以忽略该错误并继续使用 B 插件;解决方法是禁用 MyAddIn
  6. B 插件启动时,我们看到 MyAddInB 插件之前首先加载,然后出现 406 错误。
  7. 当我们卸载 MyAddIn 时,不再遇到此错误并且一切正常。
  8. 为了消除此错误,我们尝试更改注册表顺序,使 B 插件始终在 MyAddin 之前打开。
    • 这可行,但这是 Microsoft Excel 的全局更改,这意味着 B 插件将始终打开,即使我们仅启动 Excel >。这是不希望的,因为 B 插件无法让用户使用静态数据,因为 B 插件会持续实时刷新。这就是 B 插件未在注册表设置中创建条目的原因。所以注册表更改不是一个选择。我们无法在 Excel 打开时始终打开 B 插件。

My Excel addin (XLL AddIn, call it MyAddIn) is built with C#, ExcelDNA, NetOffice, VS2010. Client has another addin (let's call it B), I guess it is written in VBA.
Client says B works fine without MyAddIn. Once MyAddIn is installed, B fails with error:

Error code: 406
Error message: Non-modal forms cannot be displayed in this host application from an ActiveX DLL, ActiveX Control, or Property Page.

I did see this Microsoft resource, but I do not want to just tell the client that B addin needs changing. I want to do something to avoid this from my side.

Here is the steps reported to see the issue:

  1. When B addin is installed, it does not make any registry entry for the Microsoft Excel.
  2. When MyAddin is installed, it makes a registry entry for Microsoft Excel.
  3. Registry entries here basically tells that the addin should be opened when Excel is launched, so B addin is not launched, Excel works fine, MyAddIn works fine.
  4. Now when B addin is launched, it gives the 406 error shown above.
  5. We can ignore the error and keep working with the B addin; disabling MyAddIn is the workaround.
  6. When the B addin is launched, we see that MyAddIn is loaded first before the B addin and then get the 406 error.
  7. When we uninstall MyAddIn, this error is no longer encountered and everything works fine.
  8. To remove this error, we tried changing the registry order to make the B addin always open before MyAddin.
    • This works, but then this a global change for Microsoft Excel, which means B addin will always open, even when we launch only Excel. This is not desired, as B addin then can't let users work with the static data as the B addin keeps on refreshing real-time. That is the reason the B addin doesn't make an entry in the registry settings. So registry changes are not an option. We can’t always open B addin whenever Excel is open.

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

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

发布评论

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

评论(1

瞄了个咪的 2024-12-28 06:48:15

我没有答案,但您可以尝试以下几件事。

您可以通过执行 File | 来判断您正在处理的插件类型。选项并选择“插件”选项卡。

如果该事件在您加载 Addin B 后立即发生,则可能意味着您正在调用一个非模式对话框,但还有一些其他情况可能会给您带来类似的错误。

根据您的描述,听起来错误可能是您的插件中的对话框,也可能是其他插件中的,并且它被称为您的插件所做的某些状态更改的副作用。

要深入了解它,您需要附加一个调试器。您可以通过将 Excel 设为您的启动项目或稍后附加来实现此目的。在这种情况下,前者可能更容易。

  1. 在 Visual Studio 中,使用Project |属性 |调试,选择启动外部程序并输入 Excel 的完全限定路径名。

  2. 手动加载Addin B给自己带来错误

  3. 闯入调试器并检查调用堆栈。

这通常会但并不总是为您提供有关问题所在的良好线索,但这始终是第一步。如果它没有为您提供有用的信息(堆栈信息经常在插件之间的转换中完全丢失),您可能需要在项目中处理的任何事件中放置一些断点。即使这并不总是可靠地工作,但值得一试。

如果我不得不猜测,我会说您的外接程序中可能有一些事件处理程序导致了问题,并且您可能需要执行一些操作,例如将 .Show 更改为“.ShowDialog” ,或者将表单的处理推迟到事件处理程序之外,但这只是一个猜测。

I don't have an answer, but here are a couple of things you can try.

You can tell what type of Addin you are dealing with by executing File | Options and selecting the Addins Tab.

If the event happens as soon as you load Addin B, it probably means you are calling a non-modal dialog box as it states, but there are a few other things that could give you similar errors.

Based on your description, it sounds like the error could either be a dialog box in your Addin, or it could be in the other addin, and it gets called as a side effect of some state change your addin made.

To get to the bottom of it, you need to attach a debugger. You can do that by making Excel your Startup Project, or by attaching later. The former is probably easier in this case.

  1. In Visual Studio, Use Project | Properties | Debug, select Start external program and put in the fully qualified pathname to Excel.

  2. Load Addin B manually to give yourself the error

  3. Break into the debugger and examine the call stack.

That will frequently but not always give you good clue as to where the problem is, but it's always the first step. If it doesn't give you useful information (stack info is frequently completely lost in transitions between addins), you may want to put some breakpoints in your projects in any events you handle. Even this doesn't reliably work all the time, but it's worth a shot.

If I had to guess, I would say probably have some event handlers in your add-in that are causing the problem, And you might have to do something like change a .Show to a `.ShowDialog', or defer the processing of the form until outside the event handler but that's just a guess.

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