共用方式為


HTMLBody Property

Returns or sets a String representing the HTML body of the specified item. The HTMLBody property should be an HTML syntax string. Read/write.

Setting the HTMLBody property sets the EditorType property of the item's Inspector to olEditorHTML.

Setting the HTMLBody property will always update the Body property immediately.

expression**.HTMLBody**

*expression   * Required. An expression that returns a PostItem or MailItem object.

Remarks

Outlook blocks code that attempts to access the HTMLBody property for security reasons. If you run a third-party add-in, custom solution, or other program that uses the HTMLBody property in Office Outlook   2003, you may receive the following warning:

A program is trying to access e-mail addresses you have stored in Outlook. Do you want to allow this? If this is unexpected, it may be a virus and you should choose "No".

Example

The following Visual Basic for Applications (VBA) example creates a new **MailItem**object and sets the BodyFormat property to olFormatHTML. The body text of the e-mail item will now appear in HTML format.

Sub CreateHTMLMail()
'Creates a new e-mail item and modifies its properties.

    Dim olApp As Outlook.Application
    Dim objMail As Outlook.MailItem
    Set olApp = Outlook.Application
    'Create e-mail item
    Set objMail = olApp.CreateItem(olMailItem)

    With objMail
       'Set body format to HTML
       .BodyFormat = olFormatHTML
       .HTMLBody = "<HTML><BODY>Enter the message text here. </BODY></HTML>"
       .Display
    End With
End Sub

This Microsoft Visual Basic Scripting Edition (VBScript) example uses the Open event to access the HTMLBody property of an item. This sets the EditorType property of the item's Inspector to olEditorHTML. When the item's Body property is set, the EditorType property is changed to the default. For example, if the default e-mail editor is set to RTF, the EditorType is set to olEditorRTF.

If this code is placed in the Script Editor of a form in design time, the message boxes during run time will reflect the change in the EditorType as the body of the form changes. The final message box uses the ScriptText property to display all the VBScript code in the Script Editor.

Function Item_Open()
    'Set the HTMLBody of the item.
    Item.HTMLBody = "<HTML><H2>My HTML page.</H2><BODY>My body.</BODY></HTML>"
    'Item displays HTML message.
    Item.Display
    'MsgBox shows EditorType is 2.
    MsgBox "HTMLBody EditorType is " & Item.GetInspector.EditorType
    'Access the body and show
    'the text of the Body.
    MsgBox "This is the Body: " & Item.Body
    'After accessing, EditorType
    'is still 2.
    MsgBox "After accessing, the EditorType is " & Item.GetInspector.EditorType
    'Set the item's Body property.
    Item.Body = "Back to default body."
    'After setting, EditorType is
    'now back to the default.
    MsgBox "After setting, the EditorType is " & Item.GetInspector.EditorType
    'Access the item's
    'FormDescription object.
    Set myForm = Item.FormDescription
    'Display all the code
    'in the Script Editor.
    MsgBox myForm.ScriptText
End Function

Applies to | MailItem Object | PostItem Object

See Also | Body Property | EditorType Property | FormDescription Object | GetInspector Property | HTMLEditor Property | Inspector Object | Open Event | ScriptText Property