Convert a Word.Application to EnvDTE80.DTE2

Hello everybody

I used to create a word-file from my application. It worked with Windows XP (Office 2003), but there's an error in Windows 7 (Office 2010).

If the word-application isn't open yet, I get the error "Call was rejected by callee (HRESULT: 0x80010001 (RPC_E_CALL_REJECTED))

I used to open the word application like this:
    wordApp = (Microsoft.Office.Interop.Word.Application)Marshal.GetActiveObject("Word.Application");
catch (COMException)
    wordApp = new Microsoft.Office.Interop.Word.Application();
    wordApp.Visible = false;

Open in new window

then I found this link and I changed the code to this

object obj = null;
System.Type t = null;

// Get the ProgID for DTE 8.0.
t = System.Type.GetTypeFromProgID("Word.Application", true);
// Create a new instance of the IDE.
obj = System.Activator.CreateInstance(t, true);
// Cast the instance to DTE2 and assign to variable dte.
dte = (EnvDTE80.DTE2)obj;

Open in new window

the last line, where I try to cast the word-application to EnvDTE80.DTE2 throws an exception (HRESULT: 0x80004002 (E_NOINTERFACE)). I don't know the message for this error, because I only see the german message.

Can anyone tell me please what I'm doing wrong?

Thank you!
Who is Participating?
Sample is for EnvDTE80.DTE2, it get a EnvDTE80.DTE2 object, then cast to EnvDTE80.DTE2.

You Create a Word.Application, then you cast to Word.Application.
innovasoftAuthor Commented:
omg sometimes it's scary what kind of mistakes I make ;) seems like i didn't really get what this DTE2 is standing for.

Thank you!
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.