同时使用 VBA 和 ActiveX 插件时出现 Excel 错误 406。
我的 Excel
插件(XLL AddIn,称之为 MyAddIn
)是用 C#、ExcelDNA、NetOffice、VS2010 构建的。客户端有另一个插件(我们称之为B
),我猜它是用VBA编写的。 客户说 B
在没有 MyAddIn
的情况下工作正常。安装 MyAddIn
后,B
失败并出现错误:
错误代码:406 错误消息:无法通过 ActiveX DLL、ActiveX 控件或属性页在此主机应用程序中显示非模式表单。
我确实看到了此 Microsoft 资源,但我不想只是告诉客户B
插件需要更改。我想做点什么来避免这种情况发生。
以下是报告的查看该问题的步骤:
- 安装 B 插件后,它不会为 Microsoft
Excel
创建任何注册表项。 - 安装
MyAddin
后,它会为MicrosoftExcel
创建一个注册表项。 - 这里的注册表项基本上告诉我们,启动
Excel
时应该打开该插件,因此B
插件不会启动,Excel
工作正常,MyAddIn
工作正常。 - 现在,当
B
插件启动时,它会给出上面所示的 406 错误。 - 我们可以忽略该错误并继续使用
B
插件;解决方法是禁用MyAddIn
。 - 当
B
插件启动时,我们看到MyAddIn
在B
插件之前首先加载,然后出现 406 错误。 - 当我们卸载
MyAddIn
时,不再遇到此错误并且一切正常。 - 为了消除此错误,我们尝试更改注册表顺序,使
B
插件始终在MyAddin
之前打开。- 这可行,但这是 Microsoft
Excel
的全局更改,这意味着B
插件将始终打开,即使我们仅启动Excel
>。这是不希望的,因为B
插件无法让用户使用静态数据,因为B
插件会持续实时刷新。这就是B
插件未在注册表设置中创建条目的原因。所以注册表更改不是一个选择。我们无法在Excel
打开时始终打开B
插件。
- 这可行,但这是 Microsoft
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:
- When B addin is installed, it does not make any registry entry for the Microsoft
Excel
. - When
MyAddin
is installed, it makes a registry entry for MicrosoftExcel
. - Registry entries here basically tells that the addin should be opened when
Excel
is launched, soB
addin is not launched,Excel
works fine,MyAddIn
works fine. - Now when
B
addin is launched, it gives the 406 error shown above. - We can ignore the error and keep working with the
B
addin; disablingMyAddIn
is the workaround. - When the
B
addin is launched, we see thatMyAddIn
is loaded first before theB
addin and then get the 406 error. - When we uninstall
MyAddIn
, this error is no longer encountered and everything works fine. - To remove this error, we tried changing the registry order to make the
B
addin always open beforeMyAddin
.- This works, but then this a global change for Microsoft
Excel
, which meansB
addin will always open, even when we launch onlyExcel
. This is not desired, asB
addin then can't let users work with the static data as theB
addin keeps on refreshing real-time. That is the reason theB
addin doesn't make an entry in the registry settings. So registry changes are not an option. We can’t always openB
addin wheneverExcel
is open.
- This works, but then this a global change for Microsoft
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我没有答案,但您可以尝试以下几件事。
您可以通过执行 File | 来判断您正在处理的插件类型。选项并选择“插件”选项卡。
如果该事件在您加载
Addin B
后立即发生,则可能意味着您正在调用一个非模式对话框,但还有一些其他情况可能会给您带来类似的错误。根据您的描述,听起来错误可能是您的插件中的对话框,也可能是其他插件中的,并且它被称为您的插件所做的某些状态更改的副作用。
要深入了解它,您需要附加一个调试器。您可以通过将 Excel 设为您的启动项目或稍后附加来实现此目的。在这种情况下,前者可能更容易。
在 Visual Studio 中,使用Project |属性 |调试,选择启动外部程序并输入 Excel 的完全限定路径名。
手动加载
Addin B
给自己带来错误闯入调试器并检查调用堆栈。
这通常会但并不总是为您提供有关问题所在的良好线索,但这始终是第一步。如果它没有为您提供有用的信息(堆栈信息经常在插件之间的转换中完全丢失),您可能需要在项目中处理的任何事件中放置一些断点。即使这并不总是可靠地工作,但值得一试。
如果我不得不猜测,我会说您的外接程序中可能有一些事件处理程序导致了问题,并且您可能需要执行一些操作,例如将
.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.
In Visual Studio, Use Project | Properties | Debug, select Start external program and put in the fully qualified pathname to Excel.
Load
Addin B
manually to give yourself the errorBreak 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.