富文本电子邮件正文中的 Excel VBA URL 超链接



有谁知道如何创建一个包含URL书签的富文本电子邮件正文?

例如,这是我的代码:

Sub SendEmailUsingWord()
Dim olApp As Outlook.Application
Dim olEmail As Outlook.MailItem
Dim olInsp As Outlook.Inspector
Dim wdDoc As Word.Document
Dim strBody As String
' The body of the message, want to create a hyperlink to (e.g.) http://www.google.com but
' still display HERE.
' In HTML it would be <a href="http://www.google.com">HERE</a>
' But I want to achieve this in a Rich Text email
strBody = "Please click HERE to be fantastic!" & vbNewLine
Set olApp = New Outlook.Application
Set olEmail = olApp.CreateItem(olMailItem)
With olEmail
    .BodyFormat = olFormatRichText
    .Display
    .To = "someone@someone.com"
    .Subject = "Email Subject"
    Set olInsp = .GetInspector
    Set wdDoc = olInsp.WordEditor
    wdDoc.Range.InsertBefore strBody
    '.send
End With
End Sub

非常感谢您的帮助:)戴夫

在德米特里为我指出正确的方向后,我尝试了以下代码:

wdDoc.Hyperlinks.Add wdDoc.Range, "http://www.google.com", , , "HERE"

它解决了我的问题!

在创建电子邮件正文时,我没有考虑word.document对象,而我应该这样做。希望这对其他人有所帮助。

你的代码有一点变化。

您需要将 BODYFORMAT 添加为

.BodyFormat = olFormatHTML
设置

正文格式后,设置电子邮件的 HTML 正文

 .HTMLBody = "<HTML><H2>The body of this message will appear in HTML.</H2><BODY>Type the message text here. </BODY></HTML>" 

查看此链接以获取完整示例:

http://msdn.microsoft.com/en-us/library/office/ff869979(v=office.15).aspx

最新更新