vba 添加超链接到 Excel 电子邮件正文

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/15224280/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-08 15:05:11  来源:igfitidea点击:

Adding hyperlinks to excel email body text

excelexcel-vbavba

提问by evoandy

I am trying to generate emails from excel but want to add hyperlinks to the email body text. I want the hyperlinks to show as text and not the file paths.

我正在尝试从 excel 生成电子邮件,但想在电子邮件正文中添加超链接。我希望超链接显示为文本而不是文件路径。

How would I go about doing this?

我该怎么做呢?

I am using the below code.

我正在使用下面的代码。

    strBody = "Hello " & Range("QuoteFirstName").Value & "," & _
       vbNewLine & _
       vbNewLine & _
           "It was good to speak with you earlier today/yesterday." & _
       vbNewLine & _
       vbNewLine & _
           "[Any personal message]" & _
       vbNewLine & _
       vbNewLine


On Error Resume Next
With OutMail
    .To = StrTo
    .CC = ""
    .BCC = ""
    .Subject = StrSubject
    .Body = StrBody
    .Attachments.Add FileNamePDF
    If Send = True Then
        .Send
    Else
        .Display
    End If
End With

Can I use .Hyperlinks.Add?

我可以使用.Hyperlinks.Add吗?

采纳答案by Alex K.

Presuming your using outlook automation, switch to the HTML mail format:

假设您使用 Outlook 自动化,切换到 HTML 邮件格式:

.BodyFormat = olFormatHTML '// 2
.HTMLBody = strBody 

And use markup for the body:

并为正文使用标记:

strBody = "Hello ..<br />next line ..." & _
          "Click <a href=""http://www.foo.com"">here</a> to ..."