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 |
|
Sergey Grischenko
Add-in Express team
Posts: 7235
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);
}
} |
|