Peter.Zhao

Hi!

I created an outlook-addin for the Outlook 2007, and I tried to get the word editor property from the Inspector.Activate event, it works well in the normal cases.

But if I open a new outlook, then double click an email under the "Draft" or the "Inbox" folder, I found I can't get the Wordeditor property in the Inspector.Activate event!

And I have searched in the MSDN, it just says "In Outlook 2007, the Inspector.WordEditor property does not work in the NewInspector event. To work around this issue, implement the Inspector.Activate event, and then use the Inspector.WordEditor property in the Inspector.Activate event. "

Why we can't get the WordEditor property in the Inspector.Activate event in this case Any work around My outlook version is 12.0.4518.1014.

TIA!!!


Re: Visual Studio Tools for Office Can't get Wordeditor property from the Inspector.Activate event in the Outlook07

Misha Shneerson - MSFT

The documentation also states that:

The WordEditor property is only valid if IsWordMail returns True and the EditorType is olEditorWord. The returned WordDocument object provides access to most of the Word object model except for the following members:

Do you check those properties prior to getting the WordEditor






Re: Visual Studio Tools for Office Can't get Wordeditor property from the Inspector.Activate event in the Outlook07

Peter.Zhao

Thank you for your answer! So in the case which I described, is there any work around to get the Wordeditor





Re: Visual Studio Tools for Office Can't get Wordeditor property from the Inspector.Activate event in the Outlook07

Misha Shneerson - MSFT

You did not answer my questions Smile




Re: Visual Studio Tools for Office Can't get Wordeditor property from the Inspector.Activate event in the Outlook07

Peter.Zhao

Yes, I didn't check the IsWordMail porperty prior to getting the WordEditor. Is there any work around to get the Wordeditor



Re: Visual Studio Tools for Office Can't get Wordeditor property from the Inspector.Activate event in the Outlook07

Misha Shneerson - MSFT

This is weird. I am always able to get to the WordEditor.

Here is the code that I have written:

Code Snippet

namespace OutlookAddIn1
{
public partial class ThisAddIn
{
Outlook.Inspectors inspectors;
private void ThisAddIn_Startup(object sender, System.EventArgs e)
{
inspectors = this.Application.Inspectors;
inspectors.NewInspector += new Microsoft.Office.Interop.Outlook.InspectorsEvents_NewInspectorEventHandler(Inspectors_NewInspector);
}

void Inspectors_NewInspector(Microsoft.Office.Interop.Outlook.Inspector insp)
{
Outlook.MailItem mailIteam = insp.CurrentItem as Outlook.MailItem;
if (mailIteam != null)
{
InspectorEvents.CreateInstance(insp);
}
}

private void ThisAddIn_Shutdown(object sender, System.EventArgs e)
{
}

#region VSTO generated code

/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InternalStartup()
{
this.Startup += new System.EventHandler(ThisAddIn_Startup);
this.Shutdown += new System.EventHandler(ThisAddIn_Shutdown);
}

#endregion
}

public class InspectorEvents
{
static System.Collections.ArrayList s_inspectorEventsCollection;

Outlook.Inspector inspector;
Outlook.InspectorEvents_10_Event events;

static public InspectorEvents CreateInstance(Outlook.Inspector inspector)
{
return new InspectorEvents(inspector);
}

public InspectorEvents(Outlook.Inspector inspector)
{
if (s_inspectorEventsCollection == null)
s_inspectorEventsCollection = new System.Collections.ArrayList();

events = inspector as Outlook.InspectorEvents_10_Event;
if (events == null)
return;

events.Activate += events_Activate;
events.Close += events_Close;

// add myself to inspector's events collection to prevent
// this object from being garbage collected
s_inspectorEventsCollection.Add(this);
}

void events_Activate()
{
object oDoc = this.inspector.WordEditor;
if (oDoc != null)
{
Word.Document doc = this.inspector.WordEditor as Word.Document;
if (doc != null)
MessageBox.Show("DocumentName is: " + doc.Name);
}
}

void events_Close()
{
this.events.Activate -= events_Activate;
this.events.Close -= events_Close;

// now remove ourselves from the collection
// to allow GC to collect us.
s_inspectorEventsCollection.Remove(this);
}
}
}






Re: Visual Studio Tools for Office Can't get Wordeditor property from the Inspector.Activate event in the Outlook07

Peter.Zhao

Thank you for your patience!

Did you try the case I described: launch a new outlook07 application, then double click an email under the "Inbox" or the "Draft" folders, can you get the wordeditor In my codes, the IsWordMail is false.





Re: Visual Studio Tools for Office Can't get Wordeditor property from the Inspector.Activate event in the Outlook07

Misha Shneerson - MSFT

Yes, I tried opening messages from both Inbox and Draft folders.

I was just reading Reading and Editing E-mail in MicrosoftR Office OutlookR 2007 and it sounds like if you do not have Word 2007 installed - you might not be able to use Word's functionality.

Can you check whether this is the case for you