Vic*_*tor 29 c# com office-2007 ms-word
我为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)
Run Code Online (Sandbox Code Playgroud)
通过以下代码使控件无效时,会发生此错误:
ribbon.InvalidateControl("control-id");
Run Code Online (Sandbox Code Playgroud)
第二个例外:
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()
Run Code Online (Sandbox Code Playgroud)
在以下代码的最后一行发生此错误:
object wdStory = Word.WdUnits.wdStory;
object wdMove = Word.WdMovementType.wdMove;
WrdApp.Selection.EndKey(ref wdStory, ref wdMove)
Run Code Online (Sandbox Code Playgroud)
我该如何解决这个问题?
Vic*_*tor 57
问题解决了!
我以前安装过Office 2010,因此Windows注册表中存在一些不一致之处.要修复它们,请打开regedit
并从错误中找到CLSID.
你会发现第二个错误:
HKEY_CLASSES_ROOT\Interface\{00020970-0000-0000-C000-000000000046}
Run Code Online (Sandbox Code Playgroud)
使用子键:
看看里面的(Default)
和Version
值TypeLib
.
现在找到下面的节点,使用(Default)
值为<TypeLib ID>
.
HKEY_CLASSES_ROOT\TypeLib\<TypeLib ID>\<version>
作为这个元素的子元素,您将找到多个元素,其中之一是Version
第一个注册表.如果你检查其他元素,你会发现它们没有任何意义.删除其他人!!! 它解决了!
升级到最新的Office版本后,我开始获得相同的异常.我尝试了一些建议的修复程序,包括以类似于@Victor描述的方式清理注册表.
最终帮助(即使它可能是多种因素的组合)是'修复'安装:
Programs and Features→最新Office版→ Repair.