我为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)我如何解决这个问题?
发布于 2012-10-19 04:02:42
问题解决了!
我之前安装了Office 2010,因此Windows注册表中存在一些不一致之处。要修复它们,请打开regedit并查找错误中的CLSID。
对于第二个错误,您将找到类似的内容:
HKEY_CLASSES_ROOT\Interface\{00020970-0000-0000-C000-000000000046}使用子键:
看看TypeLib内部的(Default)和Version值。
现在,使用(Default)值作为<TypeLib ID>,找到下面的节点。
HKEY_CLASSES_ROOT\TypeLib\<TypeLib ID>\<version>
作为此元素的子元素,您将发现多个元素,其中一个是第一个注册表的Version。如果您检查其他元素,您会发现它们没有指向任何内容。删除其他的!问题解决了!
发布于 2018-01-19 18:05:05
办公室的修缮对我很管用。在我的例子中,我安装了Project,我相信它改变了配置,并且无法调用将数据从excel工作簿迁移到SQL的过程
发布于 2015-09-17 14:46:29
只需安装Office2010/ MS word / .NET可编程性支持。
https://stackoverflow.com/questions/12957595
复制相似问题