I need to replace an user selection while editing an Outlook e-mail with my custom HTML code.
I tried two approaches:
Word.Range
from the Word.Selection
.range.Copy()
to put it in the clipboardinputString
to outputString
outputString
with range.PasteSpecial(...)
Word.Range
from the Word.Selection
.range.Copy()
to put it in the clipboard.inputString
to outputString
(in Office Open XML format, knowing how to craft it to produce a specific HTML).outputString
with range.InsertXML(...)
The issues are:
insertXML
you need to have Microsoft Word installed. You can't do an insertXML
with Outlook installed alone. Look at: Impact of deploying Outlook 2007 without Word 2007 for further information.Do you know more alternatives? I can think of adding the elements myself like using InsertParagraph
, but I am not sure if I can add hyperlinks or will experience similar issues.
According to msdn, the HTMLEditor has been deprecated in Outlook 2007 - see the fourth section down, "HTML Editor".
Technically, you can still access the HTML through MailItem.HTMLBody
, but it's just a read/write string value so you wouldn't be able to find out what portion of the text is highlighted directly.
Using MailItem.getInspector.WordEditor
, you could find out what specific text is highlighted and then find and replace it in the HTMLBody via vba's Replace
, surrounded by your html.
Considering how convoluted that is, you may want to use WordEditor
to make your formatting changes directly. I didn't see anything in the link you provided that would indicate the WordEditor
object isn't available in a standalone Outlook 2007 installation, but I have the full office suite so I can't test it myself. this site describes how to do it with the WordEditor
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With