How to access MailEnvelope.item

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

How to access MailEnvelope.item
 
Helge Kunst


Guest


Hi,

I am trying to access the MailEnvelope.Item Object of a Word document with the following code:

Word.Document wdDoc = e.HostObject as Word.Document;
if (wdDoc.ActiveWindow.EnvelopeVisible==true)
{
Microsoft.Office.Interop.Outlook.MailItemClass mItem = (Microsoft.Office.Interop.Outlook.MailItemClass)wdDoc.MailEnvelope.Item;
}

I get an Error that there is no object instance. The Word Mailenvelope fields "To:" and "Subject:" are filled.

Office 2003 SP2
Visual Studio 2003
Add-in Express Version 2.2

Any Ideas?

Helge
Posted 12 Feb, 2006 08:41:25 Top
Sergey Grischenko


Add-in Express team


Posts: 7233
Joined: 2004-07-05
Hi Helge.

Please try the code below.

private void adxWordEvents_DocumentBeforeClose(object sender, AddinExpress.MSO.ADXHostBeforeActionEventArgs e)
{
Word.Window wnd = null;
Word.Document wdDoc = null;
Microsoft.Office.Core.MsoEnvelope envelop = null;

try
{
wdDoc = WordApp.ActiveDocument;
wnd = wdDoc.ActiveWindow;
if (wnd.EnvelopeVisible==true)
{
//object item = null;
Outlook._MailItem mItem = null;
try
{
envelop = wdDoc.MailEnvelope;
if (envelop != null)
{
mItem = envelop.Item as Outlook._MailItem;
if (mItem != null)
{
}
}
}
finally
{
if (mItem != null)
Marshal.ReleaseComObject(mItem);
if (envelop != null)
Marshal.ReleaseComObject(envelop);
}
}
}
catch(Exception err)
{
MessageBox.Show(err.Message);
}
finally
{
if (wnd != null)
Marshal.ReleaseComObject(wnd);
if (wdDoc != null)
Marshal.ReleaseComObject(wdDoc);
}
}
Posted 13 Feb, 2006 08:40:37 Top