2010-05-11

Adding Text To Message Body in Outlook Custom Form

I had a simple request to add some canned text to the message body of a Outlook custom form when the form was first opened, so I did this in VBScript:

Sub Item_Open()
  ...
  Item.HTMLBody = "Blah blah blah"
  ...
End Sub

Yet when I created a new item, the message body was empty! The same problem occurs with Item.Body. After the usual bit of trial-and-error, I discovered that the text only appears if you use HTMLBody or Body on the RHS of a statement:

  Dim strTest
  strTest = Item.HTMLBody
  Item.HTMLBody = "Blah blah blah"
More concisely:
  Item.HTMLBody = "Blah blah blah" & Item.HTMLBody

The text also appears if I display a message box after I add text to the message box.

It seems like the HTMLBody or Body field is not instantiated or refreshed unless it is used.

References

2 comments:

  1. does it only apply if you use htmlbody? what about the rich text version???

    ReplyDelete
  2. How do you write RTF text to the message body?

    KB291153 (above) says that all text formatting is lost if you write to the Body property.

    KB312168 (below) says that you should not assign an RTF stream to the Body property:

    OL2000: Microsoft Does Not Support Setting the "Body" Property to Rich Text Format
    http://support.microsoft.com/kb/312168/

    ReplyDelete