Microsoft KB Archive/230915

= How To Programmatically Add a Hyperlink to an HTML Message =

Article ID: 230915

Article Last Modified on 7/1/2004

-

APPLIES TO


 * Microsoft Outlook 2000 Standard Edition
 * Microsoft Outlook 98 Standard Edition

-



This article was previously published under Q230915



SUMMARY
This article explains how to programmatically add an embedded hyperlink to a new message without clicking the body of the message to format the link as a valid hyperlink. To perform this, you must provide the HTML format codes in the string you write to the HTMLBody property of the message.



MORE INFORMATION
The HTMLBody property is available from the MailItem object in the following Microsoft Outlook object models:
 * Microsoft Outlook 98 (Msoutl85.olb)
 * Microsoft Outlook 2000 (Msoutl9.olb)

If the default EditorType property of the mail client is not in HTML format, then the HTMLBody property does not preserve the HTML formatting. The data is converted to either Rich Text Format (RTF) or Text, depending on the EditorType property, and then saved in the Body property.

The following Visual Basic sample demonstrates writing HTML formatted text to a new message using the HTMLBody property:

'Requires a reference to the Outlook Object Library Dim spApplication as Outlook.Application Dim spMailItem as Outlook.MailItem

Set spApplication = New Outlook.Application Set spMailItem = spApplication.CreateItem(olMailItem) If Not spMailItem Is Nothing Then If spMailItem.GetInspector.EditorType = olEditorHTML Then spMailItem.HTMLBody = spMailItem.HTMLBody & _ "  Inserted Hyperlink  " 'HTML formatted text Else spMailItem.Body = spMailItem.Body & "Inserted Text" End If spMailItem.Save spMailItem.Close(olSave) Set spMailItem = Nothing End If Set spApplication = Nothing

Keywords: kbhowto kboutlookobj kbmsg KB230915

-

[mailto:TECHNET@MICROSOFT.COM Send feedback to Microsoft]

© Microsoft Corporation. All rights reserved.