Convert a Word.Application to EnvDTE80.DTE2

Posted on 2011-10-28
Medium Priority
Last Modified: 2013-12-16
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 http://msdn.microsoft.com/en-us/library/ms228772(VS.80).aspx 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!
Question by:innovasoft
LVL 15

Accepted Solution

x77 earned 2000 total points
ID: 37049374
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.

Author Comment

ID: 37055519
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!

Featured Post

Granular recovery for Microsoft Exchange

With Veeam Explorer for Microsoft Exchange you can choose the Exchange Servers and restore points you’re interested in, and Veeam Explorer will present the contents of those mailbox stores for browsing, searching and exporting.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
High user turnover can cause old/redundant user data to consume valuable space. UserResourceCleanup was developed to address this by automatically deleting user folders when the user account is deleted.
Whether it be Exchange Server Crash Issues, Dirty Shutdown Errors or Failed to mount error, Stellar Phoenix Mailbox Exchange Recovery has always got your back. With the help of its easy to understand user interface and 3 simple steps recovery proced…
With just a little bit of  SQL and VBA, many doors open to cool things like synchronize a list box to display data relevant to other information on a form.  If you have never written code or looked at an SQL statement before, no problem! ...  give i…
Suggested Courses
Course of the Month16 days, 8 hours left to enroll

864 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question