Unable to cast COM object of Office Interop Word
Asked Answered
A

5

11

My application has a feature to export to Microsoft Word, but it hasn't worked since I've upgraded from Microsoft Office 2010 to Microsoft Office 2013.

Here is the code:

Microsoft.Office.Interop.Word.Application appVersion = new Microsoft.Office.Interop.Word.Application();
appVersion.Visible = false;

and this is the error message:

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: No such interface supported (Exception from HRESULT: 0x80004002 (E_NOINTERFACE)).

Someone told me to edit the registry, but the IID "{00020970-0000-0000-C000-000000000046}" does not exist in my registry.

Amaliaamalie answered 12/3, 2014 at 2:0 Comment(1)
That's what the exception message means, COM could not find the registry key either. Reinstall after trying to find out why the registry is corrupted. And do try to run code on an STA thread, this marshaling isn't very cheap.Waterlogged
R
5

Running a repair installation of Office usually resolves that issue.

Reiko answered 20/3, 2014 at 11:47 Comment(1)
In the case that this doesn't work, is there any further debug that can be performed?Ostensive
C
2

I switched from using Word Interop to using Late Binding. Quick fix that didn't affect refactoring a lot of code...

Before:

OfficeWord.Application msword = new OfficeWord.Application();

After:

Type wordType = Type.GetTypeFromProgID("Word.Application");
dynamic msword = Activator.CreateInstance(wordType);

Solved my issues on a bunch of corporate computers that started seeing this problem after an Office upgrade by Client Support.

Clementinaclementine answered 22/6, 2020 at 17:2 Comment(2)
now I know a real use for dynamic, thanks ))Onset
It worked for me as many other solutions did not work who suggest to repair office or install again etcGwenny
C
1

I had the exact same problem and reinstalling Office 2013 solved my issue.

Chord answered 15/8, 2015 at 5:5 Comment(0)
E
0

I know it is late, but since I had the same issue, I found a solution here.

It might help others in the future.

Edge answered 6/5, 2023 at 12:9 Comment(0)
T
-1

Old question, however I ran into the same thing, same exact error message when trying to create a new word application. The problem was simple, once I closed VS in frustration and went to do other work. When I opened word, it had retrieved documents that had not been saved when Word closed down and wanted to know what I wanted to do with them. I told it to delete them, closed word and my code worked fine. Still working on a way around this but I thought I would drop this in here to save someone else from reinstalling office when it was something simple.

Traumatism answered 3/9, 2020 at 16:4 Comment(0)

© 2022 - 2025 — McMap. All rights reserved.