Question

So here's the problem. When an inline response is opened I'm able to edit it without any problem. Then, when I run the spell check through the word editor, I lose the ability to edit through the HMTLBody of the email. By that I mean that if I do something like this:

email.HTMLBody = email.HTMLBody.Replace("cat", "dog");

it won't change the body in the email. If I highlight email after the changes are made, the HTMLBody will show the changes, but it won't show up in the email.

Now, if I do all of the editing first and then do the spellcheck, it will go through all of the text that is wrong, but it won't change the actual email text. This only happens for body of the email by the way. I can change the To:, CC:, and Subject: fields just fine not matter what happens. It also only affects the inline responses and not any email that is popped out into it's own inspector. I can start a reply as an inline and then pop it and the problem will not occur.

This is the way i'm doing the spell checking

Outlook.Inspector insp = email.GetInspector;
Word.Document Doc = insp.WordEditor;
if(!doc.SpellingChecked)
{
    doc.CheckSpelling();
    email.Save();
}

If you need any information let me know.

EDIT

So, putting a little more thought about what @Dmitry said, I decided to go back and work on using the .WordEditor from the email. This are the results.

I was able to edit the email body pretty well using the word editor, but it would reformat the entire email (remove reply/forward separation lines) and color the entire email with the reply color (blue for me). I was able to fix this with the by using the start and end value in the .Range of the document like so:

Word.Document emailEditor = GetCurrentMailWordEditor(); // A function I use to retrieve the correct editor
Word.Range rng = emailEditor.Range(startIndex, endIndex); // To get only the specific part I want to change
rng.Text = rng.Text.Replace("cat", "dog");

instead of

Word.Document emailEditor = GetCurrentMailWordEditor();
Word.Range rng = emailEditor.Range();
rng.Text = rng.Text.Replace("cat", "dog");

The spell checking I was able to fix by getting the .WordEditor from the correct source like so:

Word.Document doc;
if(this.Application.ActiveInspector() != null)
{
    OutlookInspector insp = this.Application.GetActiveInspector();
    doc = insp.WordEditor;
}
else
{
    Outlook.Explorer exp = this.Applicaotn.GetActiveExplorer();
    doc = exp.ActiveInlineResponseWordEditor;
}

if(!doc.SpellingChecked)
{
    doc.CheckSpelling();
    email.Save();
}
Was it helpful?

Solution

If you already have an instance of the Word's Document object, why not do the text replacement using the Word Object Model as well?

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top