【发布时间】:2012-10-09 02:02:22
【问题描述】:
我为 Microsoft Office Word 构建了一个插件。当 Word 以管理员身份运行时,使用加载项没有问题,但当它不以管理员身份运行时,访问功能区元素有两个常见异常。
第一个例外:
Unable to cast COM object of type 'System.__ComObject' to interface type 'Microsoft.Office.Core.IRibbonUI'. This operation failed because the QueryInterface call on the COM component for the interface with IID '{000C03A7-0000-0000-C000-000000000046}' failed due to the following error: could not be found. (Exception from HRESULT: 0x80030002 (STG_E_FILENOTFOUND)).
at Microsoft.Office.Core.IRibbonUI.InvalidateControl(String ControlID)
当控件被以下代码失效时会出现此错误:
ribbon.InvalidateControl("control-id");
还有第二个例外:
Unable to cast COM object of type 'Microsoft.Office.Interop.Word.ApplicationClass' to interface type 'Microsoft.Office.Interop.Word._Application'. This operation failed because the QueryInterface call on the COM component for the interface with IID '{00020970-0000-0000-C000-000000000046}' failed due to the following error: could not be found. (Exception from HRESULT: 0x80030002 (STG_E_FILENOTFOUND)).
at Microsoft.Office.Interop.Word.ApplicationClass.get_Selection()
此错误出现在以下代码的最后一行:
object wdStory = Word.WdUnits.wdStory;
object wdMove = Word.WdMovementType.wdMove;
WrdApp.Selection.EndKey(ref wdStory, ref wdMove)
我该如何解决这个问题?
【问题讨论】:
-
在其他电脑上也能用吗?前几天我打破了注册表(在同事的计算机上)并且遇到了与所有使用 COM 组件的程序类似的问题。如果它可以在另一台计算机上运行,我会解释我做了什么来修复它。
-
是的,在开发计算机上工作。只是在试机不工作。也许是因为我安装(和卸载)了许多版本的 Office(2007、2007-64、2010、2010-64)
-
天哪。那么,测试机运行的是什么操作系统?
-
Windows 7 64 位和 Office 2007 32 位
-
但是为什么当我以管理员身份运行时一切正常?
标签: c# com ms-word office-2007