using word editor in outlook add-in

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

using word editor in outlook add-in
 
Roger Levy




Posts: 5
Joined: 2017-03-28
I catch the Outlook Send event and add to the email that the user has composed by adding to MailItem.body. However in some cases I need to send a completely different second email to the same recipients. Because I cannot always determine the sender's email address (my last topic) I decided to copy the mail item and delete everything that the user wrote by doing this ...

Dim oDoc As Word.Document = TryCast(oOpenMail.GetInspector.WordEditor, Word.Document)
oDoc.Range(0, oOpenMail.Body.Length - 1).Delete(Word.WdUnits.wdCharacter)

I then hope to add a new html body. The deletion seems to work but there is a prompt asking whether the document should be saved. I have searched a lot of articles and forums but I cannot find a method that both accepts my edits and does not prompt.
Posted 10 Apr, 2017 12:22:29 Top
Andrei Smolin


Add-in Express team


Posts: 14094
Joined: 2006-05-11
Hello Roger,

To avoid the prompt, save the item yourself.

Regards from Belarus (GMT+3),

Andrei Smolin
Add-in Express Team Leader
Posted 11 Apr, 2017 05:43:06 Top
Roger Levy




Posts: 5
Joined: 2017-03-28
I tried SaveAs on both the editor document and Outlook message but neither prevented the prompt from appearing. Since I couldn't successfully edit the original MailItem I copied it and worked on the copy. It seems that there is no active editor on a copy so I didn't encounter a problem about saving changes. I was able to do what I wanted with the copy by assigning to .body and .htmlbody. This worked for me because I was sending 2 emails but I think I would still be in trouble if my need was to edit only the original and send it. BTW, this is Outlook 2003, if that matters.

Roger
Posted 11 Apr, 2017 16:20:16 Top
Andrei Smolin


Add-in Express team


Posts: 14094
Joined: 2006-05-11
Hello Roger,

If you call MaitItem.Copy to create a copy of the specified email, and modify the copy, you should call MailItem.Save on the copy. Not MailItem.SaveAs.

Roger Levy writes:
It seems that there is no active editor on a copy


Are you saying that calling Inspector.WordEditor for the copy email returns Nothing?

Roger Levy writes:
Dim oDoc As Word.Document = TryCast(oOpenMail.GetInspector.WordEditor, Word.Document)


I assume that you release the oDoc and oOpenMail variables. Still, oOpenMail.GetInspector creates and leaves unreleased an Inspector object: you need to release it.

Regards from Belarus (GMT+3),

Andrei Smolin
Add-in Express Team Leader
Posted 12 Apr, 2017 05:08:35 Top