[英]Excel VBA URL hyperlink in RichText email body
有谁知道如何创建一个包含URL书签的RichText电子邮件正文?
例如,这是我的代码:
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
设置BODYFORMAT后 ,设置电子邮件的HTMLBODY 。
.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
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.