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

有谁知道如何创build一个RichText电子邮件正文,它有一个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 (eg) 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"

它解决了我的问题!

创build电子邮件正文时,我并没有考虑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