如何将列中的超链接插入Outlook电子邮件正文
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了如何将列中的超链接插入Outlook电子邮件正文相关的知识,希望对你有一定的参考价值。
我的列“AB”有一个超链接,我希望通过VBA将其包含在电子邮件中。
超链接每行更改。我可以通过文本拉列,但电子邮件没有显示超链接。
如何将其显示为超链接?
Dim OutApp As Object
Dim OutMail As Object
Dim strto As String, strcc As String, strbcc As String
Dim strsub As String, strbody As String
Set OutApp = CreateObject("Outlook.Application")
Set OutMail = OutApp.CreateItem(0)
strto = Cells(FormulaCell.Row, "Y").Value
strcc = ""
strbcc = ""
strsub = "MCR FORM"
strbody = "Hi " & Cells(FormulaCell.Row, "O").Value & vbNewLine & vbNewLine & _
"You have a open MCR that needs attention. Please Find the attachted MCR Form for material : " & Cells(FormulaCell.Row, "E").Value & _
vbNewLine & vbNewLine & Cells(FormulaCell.Row, "AB").Value & vbNewLine & vbNewLine & "Thank you!"
With OutMail
.To = strto
.CC = strcc
.BCC = strbcc
.Subject = strsub
.Body = strbody
'You can add a file to the mail like this
.Attachments.Add ("P:Inventory ControlPublicMCR Form Master.xlsm")
.Display ' or use .Send
End With
Set OutMail = Nothing
Set OutApp = Nothing
End Sub
vbNewLine & vbNewLine & Cells(FormulaCell.Row, "AB").Value &
我相信上面的代码需要引用一个HREF链接?
答案
示例将显示Hyperlink Click Here
.htmlBody = "<A href=" & Sht.Range("A1") & "> Click Here </A>"
或者这将显示值A1作为链接
"<A href=" & Sht.Range("A1") & ">" & Sht.Range("A1") & "</A>" &
完整代码
Option Explicit
Public Sub Example()
Dim Sht As Excel.Worksheet
Set Sht = ThisWorkbook.Worksheets("Sheet1")
Dim OutApp As Object
Set OutApp = CreateObject("Outlook.Application")
Dim OutMail As Object
Set OutMail = OutApp.CreateItem(0)
With OutMail
.To = ""
.CC = ""
.BCC = ""
.Subject = ""
.HTMLBody = "Hi " & vbNewLine & vbNewLine & _
"You have a open MCR that needs attention. " & _
vbNewLine & vbNewLine & _
"<A href=" & Sht.Range("A1") & "> Click Here </A>" & _
vbNewLine & vbNewLine & _
"Thank you!"
'You can add a file to the mail like this
.Display ' or use .Send
End With
Set OutMail = Nothing
Set OutApp = Nothing
End Sub
Option Explicit Statement (Visual Basic)
强制显式声明文件中的所有变量,或允许隐式声明变量。
以上是关于如何将列中的超链接插入Outlook电子邮件正文的主要内容,如果未能解决你的问题,请参考以下文章
将 Excel 范围内的超链接传输到 Outlook 电子邮件
从 Excel 打开 Word 文档并将内容粘贴到 Outlook 邮件的正文