How to create formatted messages in Microsoft Outlook
If you need to send formatted messages in Outlook or add formatting to the body of a contact or other item, the methods available depend on several factors:
- Version of Outlook
- Whether the item's format is HTML or rich-text (RTF). Contact, appointment, task, and journal items are always RTF.
- In versions before Outlook 2007, whether Word is the email editor
To create an HTML format message in any version, build a string that includes not just your text, but also the HTML tags that control the formatting. Then assign your string to the HTMLBody property.
An alternative approach is to set the HTMLBody property to your text (even without tags) and thus force the message to use HTML format. In versions of Outlook before Outlook 2007, you can use the Inspector.HTMLEditor property to return an HTML Document Model object from an HTML-format message or post item. (FYI, this causes the entire document to load as if you'd opened it in a browser.)
Word or Excel "Office Envelope"
If your goal is to send a message that includes a body with some complex formatting, both Word and Excel support a technique for sending the content from a document or worksheet as an HTML-format email message. For a Word code sample, see:
RTF or HTML with WordMail
If you compose a message in rich-text format (RTF) or HTML using WordMail as the editor, you can use the Inspector.WordEditor property to return a Word Document object, then use Word techniques to change fonts, etc. For a sample, see:
In Outlook 2007, Word is the editor for all items except sticky notes. That means that you can use WordEditor to format item bodies for contact, appointment, task, and journal items, as well as messages and posts. These samples do not deal specifically with formatting issues but do demonstrate the basics of working with Word objects in Outlook 2007:
If you don't know Word programming that well, you can use the macro recorder in Word to get a general idea of what objects and property values are relevant to a particular formatting task and then convert that Word macro into Outlook VBA code using the technique demonstrated at:
RTF with CDO
To use this method, you create the RTF formatted text -- either doing raw RTF (if you're a glutton for punishment), maybe using a rich-text control to pick up the user's formatting choices or using Word as an intermediary -- then write it to the message using CDO and this special DLL. This article explains how:
The Redemption development tool, commonly used to avoid Outlook security prompts, offers a SafeInspector object that makes it much easier to format and perform other operations with selected text.
Redemption also exposes an RTFBody property on each item. Of course, you still have to write your own RTF code, which is beyond the scope of this site. The RTF resources in the More Information listing should help.