I built an add-in for Microsoft Office Word. There isn't an issue using the add-in when Word is ran as Administrator, but when it's not ran as an Administrator, there are two common exceptions accessing Ribbon elements.
The first Exception:
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)
This error occurs when the Control is invalidated by the following code:
ribbon.InvalidateControl("control-id");
And the second Exception:
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()
This error occurs on the last line of the following code:
object wdStory = Word.WdUnits.wdStory;
object wdMove = Word.WdMovementType.wdMove;
WrdApp.Selection.EndKey(ref wdStory, ref wdMove)
How can I fix this problem?
Problem solved!
I have previously installed Office 2010, so there are some inconsistences in Windows Registry.
To fix them, open the regedit
and find for the CLSID from the error.
You will find something like that for the second error:
HKEY_CLASSES_ROOT\Interface\{00020970-0000-0000-C000-000000000046}
With the subkeys:
Take a look at the (Default)
and Version
values inside of TypeLib
.
Now find the node below, using the (Default)
value as <TypeLib ID>
.
HKEY_CLASSES_ROOT\TypeLib\<TypeLib ID>\<version>
As child of this elements you will find more than one element, one of then is the Version
of the first registry. If you inspect the others elements, you will find that they point to nothing. Remove the others!!! It's solved!
I started getting the same exception after upgrading to the latest Office version. I tried a number of suggested fixes including cleaning up the registry in a way similar to what @Victor described.
What eventually helped (even though it might have been a combination of factors) was 'repairing' the installation:
Programs and Features → latest Office version → Repair.
The office repair worked for me. In my case I had installed Project which I believe altered the config and was unable to call up a procedure to migrate data from an excel workbook to SQL
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With