Hi!
I have the following code within a COM Addin and Outlook 2007:
Outlook.MailItem mi = ActiveExplorer.Selection[1] as Outlook.MailItem;
if ( mi != null )
{
Outlook.Inspector objInsp = mi.GetInspector;
Word.Do***ent objDoc = objInsp.WordEditor as Word.Do***ent;
objDoc.Content.InsertAfter( "This is a test! " ); // PROBLEM HERE
}
The code is executed within OnExplorerSelectionChange event. When
executed, the InsertAfter method throws a COMException with message
"This method or property is not available because the do***ent is
locked for editing.". Therefore, I tried to unprotect the do***ent
with
object missing = System.Reflection.Missing.Value;
Word.WdProtectionType protectionType = objDoc.ProtectionType;
if ( protectionType != Word.WdProtectionType.wdNoProtection )
objDoc.Unprotect( ref missing );
before calling InsertAfter method. This seems to work for HTML mail,
but does NOT work for plain text mail. In case of a text mail, the
objDoc.Unprotect( ref missing ); method throws a COMException with
message "This command is not available".
Is there a way to get around this issue? Any help would be greatly
appreciated.