通过打开文件启动 Excel 时,不加载 Excel 的 COM 加载项

发布于 2024-08-08 00:30:22 字数 3051 浏览 2 评论 0原文

一些用户报告说,如果他们通过双击 Excel 文件来启动 Excel,则加载项将无法加载。但是,如果他们通过“开始”菜单(或快速启动工具栏)打开 Excel,则加载项可以正常加载。

一些细节,如果它们有帮助的话:

  • 它是一个 COM 插件,用 VB6 编写。
  • Windows XP/Excel 2003 和 Vista/Excel 2007 系统上已报告该问题。
  • 该加载项实现了 IDTEXtensibility2。
  • 启动模式设置为“启动时加载”。

任何关于原因或如何解决此问题的想法将不胜感激。

更新:我相信我已经找到了解决这个问题的方法。

注册 IDTExtensibility2 dll 时,它会自动为加载行为、加载项名称等创建 HKCU 条目。但我还让我的安装文件将加载项注册到 HKLM,以便它可供所有用户使用机器。这导致系统上存在双重注册表项。

我不认为这会是问题的原因。我手动编辑了 HKCU 条目,Excel 似乎忽略了它们并遵循 HKLM 条目。然而,我收到另一位开发人员的提示,解释说他们也遇到了同样的问题,他们的解决方案是删除重复的注册表项。我尝试过,它似乎已经为报告该错误的(极少数)人解决了问题。

下面的 Inno Setup 代码将添加 HKLM 条目,仔细检查加载行为是否正确(因为我很偏执),然后删除 HKCU 条目。在您看到全部大写的地方替换您的文件属性。

[Registry]
Root: HKLM; Subkey: Software\Microsoft\Office\Excel\Addins\CONNECT_CLASS; Flags: uninsdeletekey
Root: HKLM; Subkey: Software\Microsoft\Office\Excel\Addins\CONNECT_CLASS; ValueType: string; ValueName: FriendlyName; ValueData: ADDIN_NAME
Root: HKLM; Subkey: Software\Microsoft\Office\Excel\Addins\CONNECT_CLASS; ValueType: string; ValueName: Description; ValueData: ADDIN_DESC
Root: HKLM; Subkey: Software\Microsoft\Office\Excel\Addins\CONNECT_CLASS; ValueType: dword; ValueName: LoadBehavior; ValueData: 3
Root: HKLM; Subkey: Software\Microsoft\Office\Excel\Addins\CONNECT_CLASS; ValueType: dword; ValueName: CommandLineSafe; ValueData: 0


// Set load behavior to on start up
procedure ResetAddinRegKeys();
var
  bUpdate : Boolean;
  LoadBehaviorKey : Cardinal;

begin
  if RegQueryDWordValue(HKEY_LOCAL_MACHINE, 'SOFTWARE\Microsoft\Office\Excel\Addins\CONNECT_CLASS', 'LoadBehavior', LoadBehaviorKey) then begin
    if LoadBehaviorKey <> 3 then begin
      bUpdate := True;
    end;
  end else begin
    bUpdate := True;
  end;

  if bUpdate = True then begin
    RegWriteDWordValue(HKEY_LOCAL_MACHINE, 'SOFTWARE\Microsoft\Office\Excel\Addins\CONNECT_CLASS','LoadBehavior', 3);
  end;

  if RegKeyExists(HKEY_CURRENT_USER, 'SOFTWARE\Microsoft\Office\Excel\Addins\CONNECT_CLASS') then begin
    if RegDeleteKeyIncludingSubkeys(HKEY_CURRENT_USER, 'SOFTWARE\Microsoft\Office\Excel\Addins\CONNECT_CLASS') then begin;
      //MsgBox('Duplicate keys deleted', mbInformation, MB_OK);
    end;
  end;
end;

function GetCustomSetupExitCode: Integer;
begin
  ResetAddinRegKeys;
  Result := 0;
end;

对于我的 MSI 安装程序,我让安装的提交部分调用以下 VBScript:

Sub RemoveAddinHKCUKeys()
    On Error Resume Next 
    Dim WshShell
    Set WshShell = WScript.CreateObject("WScript.Shell")

    WshShell.RegDelete "HKCU\SOFTWARE\Microsoft\Office\Excel\Addins\CONNECT_CLASS\CommandLineSafe"
    WshShell.RegDelete "HKCU\SOFTWARE\Microsoft\Office\Excel\Addins\CONNECT_CLASS\Description"
    WshShell.RegDelete "HKCU\SOFTWARE\Microsoft\Office\Excel\Addins\CONNECT_CLASS\FriendlyName"
    WshShell.RegDelete "HKCU\SOFTWARE\Microsoft\Office\Excel\Addins\CONNECT_CLASS\LoadBehavior"
    WshShell.RegDelete "HKCU\SOFTWARE\Microsoft\Office\Excel\Addins\CONNECT_CLASS\"

    If Err.Number <> 0 The Err.Clear
End Sub

Several users have reported that if they launch Excel by double-clicking an Excel file, the add-in will not load. But, if they open Excel via the Start menu (or Quick launch toolbar) the add-in loads fine.

Some details, in case they help:

  • It is a COM add-in, written in VB6.
  • The problem has been reported on Windows XP/Excel 2003 and Vista/Excel 2007 systems.
  • The add-in implements IDTExtensibility2.
  • The start mode is set to "Load on Startup".

Any thoughts on the cause or how to troubleshoot this would be greatly appreciated.

Update: I believe I have found a solution to this problem.

When an IDTExtensibility2 dll is registered, it automatically creates HKCU entries for the load behavior, add-in name, etc. But I also had my setup file register the add-in to HKLM, so that it would be available to all users on a machine. This caused double registry entries on the system.

I didn't think this would be the cause of the problem. I manually edited the HKCU entries and Excel seemed to ignore them and follow the HKLM entries. However, I received a tip from another developer explaining that they had the same problem, and their solution was to delete the duplicate registry entries. I tried it and it seems to have resolved the problem for the (very small number of) people who reported the bug.

The Inno Setup code below will add the HKLM entries, double-check that the load behavior is correct (because I'm paranoid), then delete the HKCU entry. Substitite your file attributes wherever you see ALL CAPS.

[Registry]
Root: HKLM; Subkey: Software\Microsoft\Office\Excel\Addins\CONNECT_CLASS; Flags: uninsdeletekey
Root: HKLM; Subkey: Software\Microsoft\Office\Excel\Addins\CONNECT_CLASS; ValueType: string; ValueName: FriendlyName; ValueData: ADDIN_NAME
Root: HKLM; Subkey: Software\Microsoft\Office\Excel\Addins\CONNECT_CLASS; ValueType: string; ValueName: Description; ValueData: ADDIN_DESC
Root: HKLM; Subkey: Software\Microsoft\Office\Excel\Addins\CONNECT_CLASS; ValueType: dword; ValueName: LoadBehavior; ValueData: 3
Root: HKLM; Subkey: Software\Microsoft\Office\Excel\Addins\CONNECT_CLASS; ValueType: dword; ValueName: CommandLineSafe; ValueData: 0


// Set load behavior to on start up
procedure ResetAddinRegKeys();
var
  bUpdate : Boolean;
  LoadBehaviorKey : Cardinal;

begin
  if RegQueryDWordValue(HKEY_LOCAL_MACHINE, 'SOFTWARE\Microsoft\Office\Excel\Addins\CONNECT_CLASS', 'LoadBehavior', LoadBehaviorKey) then begin
    if LoadBehaviorKey <> 3 then begin
      bUpdate := True;
    end;
  end else begin
    bUpdate := True;
  end;

  if bUpdate = True then begin
    RegWriteDWordValue(HKEY_LOCAL_MACHINE, 'SOFTWARE\Microsoft\Office\Excel\Addins\CONNECT_CLASS','LoadBehavior', 3);
  end;

  if RegKeyExists(HKEY_CURRENT_USER, 'SOFTWARE\Microsoft\Office\Excel\Addins\CONNECT_CLASS') then begin
    if RegDeleteKeyIncludingSubkeys(HKEY_CURRENT_USER, 'SOFTWARE\Microsoft\Office\Excel\Addins\CONNECT_CLASS') then begin;
      //MsgBox('Duplicate keys deleted', mbInformation, MB_OK);
    end;
  end;
end;

function GetCustomSetupExitCode: Integer;
begin
  ResetAddinRegKeys;
  Result := 0;
end;

For my MSI installer, I have the commit section of the installation call the following VBScript:

Sub RemoveAddinHKCUKeys()
    On Error Resume Next 
    Dim WshShell
    Set WshShell = WScript.CreateObject("WScript.Shell")

    WshShell.RegDelete "HKCU\SOFTWARE\Microsoft\Office\Excel\Addins\CONNECT_CLASS\CommandLineSafe"
    WshShell.RegDelete "HKCU\SOFTWARE\Microsoft\Office\Excel\Addins\CONNECT_CLASS\Description"
    WshShell.RegDelete "HKCU\SOFTWARE\Microsoft\Office\Excel\Addins\CONNECT_CLASS\FriendlyName"
    WshShell.RegDelete "HKCU\SOFTWARE\Microsoft\Office\Excel\Addins\CONNECT_CLASS\LoadBehavior"
    WshShell.RegDelete "HKCU\SOFTWARE\Microsoft\Office\Excel\Addins\CONNECT_CLASS\"

    If Err.Number <> 0 The Err.Clear
End Sub

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

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

发布评论

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

评论(2

随遇而安 2024-08-15 00:30:22

已经过去很长时间了,我的记忆已经模糊了,但我确实记得如果主机(Excel、Word)作为嵌入对象启动,则启动 COM 加载项会出现问题。也就是说,您有一个嵌入了 Excel 文档的 Word 文档(您实际上在 Word 中看到了 Excel 单元格)。当您双击嵌入的 Excel 文件来使用它时,Excel 将启动,但 Excel 不会加载其 COM 加载项。然后,当您以任何其他方式启动 Excel 时,您实际上只是使用曾经/已经从嵌入对象运行的 Excel,并且它不会包含您的 COM 加载项。

这似乎不是你的问题,但我想你可能需要一些同情。 ;)

您是否使用 VB6 中的插件设计器?我没有遇到任何问题,但您尝试废弃它并直接在类中实现 IDTExtensibility2,然后编写自己的注册表项以将其注册为 COM 加载项。或者在您不使用设计器的情况下以其他方式执行此操作。

要尝试的一件事是将加载项注册为计算机范围的加载项,而不仅仅是用户加载项。对于设计器,您只能注册为用户加载项。 (尽管有一个解决方法)。

你能重现它吗?是否有任何 IDTEXtensibility2 方法被调用?

我认为其他加载项可能会干扰。您可以下载我的 COM 加载项实用程序来查看加载了哪些加载项(Office 应用程序中的 COM 加载项窗口仅显示用户加载项,而不显示计算机加载项。)

http://www.amos Fivesix.com/download/stackoverflow/

如果加载项完全停止加载, Office 应用程序可能已禁用它。转到帮助|关于 |禁用项目并查看它是否存在。

Excel 有一些与 DDE 相关的愚蠢选项(资源管理器通常用它来打开其他应用程序中的文档)。选项|一般|忽略其他应用程序。看看这是否有影响。

如果您无法重现问题,但您的客户端可以,您可以为他们编写一个特殊版本来记录 IDT... 事件以查看它们是否正在发生。向他们发送一个宏,用于检查 Excel.Application.Addins 以查看您的加载项是否存在(我知道 Word 有该对象模型,不确定 Excel 是否有,所以如果没有,请原谅我)。

It's been a long time so my memory is foggy, but I do recall problems with getting COM add-ins to start if the host (Excel, Word) is started as an embedded object. That is, you have a Word document with an Excel document embedded in it (you actually see the Excel cells there in Word). When you double-click the embedded Excel file to work with it, Excel is started, but Excel does not load its COM Add-ins. Then when you start Excel in any other way, you're really just using the Excel that was/is already running from the embedded object and it won't have your COM add-ins.

That doesn't appear to be your problem but I thought you might like some sympathy. ;)

Are you using the Add-in Designer in VB6? I haven't had problems with it, but you try scrapping it and implementing IDTExtensibility2 directly in a class and then writing your own registry entries to register it as a COM add-in. Or do this the otherway around of you're not using the designer.

One thing to try is to register the add-in as a machine-wide add-in, rather than just a user add-in. With the designer you can only register as a user add-in. (Though there is a work around for that).

Are you able reproduce it? Are any of the IDTExtensibility2 methods getting called at all?

I suppose it's possible other add-ins might be interfering. You can download my COM Add-In utility to look at what add-ins are loaded (the COM Add-ins windows in the Office apps only show you the user add-ins, not the machine add-ins.)

http://www.amosfivesix.com/download/stackoverflow/

If the add-in completely stops loading, the Office app may have disabled it. Go to Help | About | Disabled Items and see if it's there.

Excel has some goofy options related to DDE (which is what Explorer uses to open documents in other apps usually.) Tools | Options | General | Ignore other applications. See if that makes a difference.

If you can't reproduce the problem, but your client can, you could write a special version for them that logs the IDT... events to see if they are happening. Send them a macro that checks Excel.Application.Addins to see if you add-in is there (I know Word has that object model, not sure about Excel so forgive me if it does not).

俯瞰星空 2024-08-15 00:30:22

只需 5 步即可轻松完成

  1. 打开 Excel
  2. 转到文件>选项>加载项
  3. 转到管理:然后选择禁用项目,然后单击转到
  4. 在新窗口中找到您的加载项,然后单击启用
  5. 重新启动 Excel

Very easy in 5 steps

  1. Open Excel
  2. Go to File>Options>Add-Ins
  3. Go to Manage: then select Disabled Items then Click Go
  4. In new windows Find your add-ins and click Enable
  5. Restart Excel
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文