HRESULT Exception : 0x80020005 (DISP_E_TYPEMISMATCH)

Add-in Express™ Support Service
That's what is more important than anything else

HRESULT Exception : 0x80020005 (DISP_E_TYPEMISMATCH)
ADXAddinModule.CurrentInstance.HostApplication to Word._Application 
Bakary Djiba




Posts: 6
Joined: 2009-06-22
Hi,
I am a new ADX product user.
When I try to open a new word document in my addin by using AddinExpress.MSO.ADXAddinModule.CurrentInstance.HostApplication that I cast to Word._Application before, it throws a HRESULT Exception : 0x80020005 (DISP_E_TYPEMISMATCH).
The HostApplication real type is Word.ApplicationClass.
I open the document by this way:


AddinModule addinModule = (AddinModule)AddinExpress.MSO.ADXAddinModule.CurrentInstance;
object hostApp = addinModule.HostApplication;
Word._Application wordApp = hostApp as Word._Application;
Word.Document doc = wordApp.Documents.Add(ref filename, ref missing, ref missing, ref missing);
doc.Activate();


Is there the best way to do it?
Help, please.
Posted 22 Jun, 2009 06:36:23 Top
Andrei Smolin


Add-in Express team


Posts: 18821
Joined: 2006-05-11
Hi Bakary,


//Word._Application wordApp = hostApp as Word._Application; 
Word.Document doc = addinModule.WordApp.Documents.Add(ref filename, ref missing, ref missing, ref missing); 


This is the only thing I would change in your code; it is a minor one, however.


Andrei Smolin
Add-in Express Team Leader
Posted 22 Jun, 2009 11:42:41 Top
Andrei Smolin


Add-in Express team


Posts: 18821
Joined: 2006-05-11
Hi Bakary,

Try using three separate variables to pass Type.Missing to the Add method.


Andrei Smolin
Add-in Express Team Leader
Posted 22 Jun, 2009 14:41:15 Top
Bakary Djiba




Posts: 6
Joined: 2009-06-22
Hi Andrei,

Thank for your replay.


Word.Document doc = addinModule.WordApp.Documents.Add(ref filename, ref missing, ref missing, ref missing);


Works well.

Regards,
Posted 23 Jun, 2009 05:00:55 Top