在电子邮件文本正文中添加指向文件位置的可点击链接

问题描述 投票:0回答:1

我有发送电子邮件的 Excel VBA 代码。
从各个单元格中提取数据以填充电子邮件中的文本正文。

我想在电子邮件文本正文中添加一个可单击的链接,指向位于单元格 AM22 中的文件位置。

Sub email_from_excel_basic()

Dim emailapplication As Object
Dim emailitem As Object
Dim link As String

Set emailapplication = CreateObject("Outlook.Application")
Set emailitem = emailapplication.createitem(0)

' build the email
emailitem.to = Range("Handover!D9").Value
emailitem.Subject = "Handover Created."
emailitem.Body = "Handover created to carry out the following:" & vbNewLine & vbNewLine & Range("Handover!AL17").Value & "    " & Range("Handover!AM17").Value & vbNewLine & Range("Handover!AL18").Value & "  " & Range("Handover!AM18").Value & vbNewLine & Range("Handover!AL19").Value & "  " & Range("Handover!AM19").Value & vbNewLine & Range("Handover!AL20").Value & "  " & Range("Handover!AM20").Value & vbNewLine & Range("Handover!AL21").Value & "  " & Range("Handover!AM21").Value & vbNewLine & Range("Handover!AL22").Value & "  " & Range("Handover!AM22").Value

' send the email
emailitem.send

Set emailitem = Nothing
Set emailapplication = Nothing

End Sub

我尝试添加范围,但它填充单元格 AM22 中的文本而不是链接。

excel vba email outlook hyperlink
1个回答
0
投票

不要使用纯文本

Body
属性,而是使用
HTMLBody
并使用包含
<a>
链接的 HTML 数据填充其值。

另请记住,链接指向的文件的位置必须可由预期接收者访问 - 它不能指向运行脚本的计算机上的本地文件。如果不是这种情况,请考虑将文件添加为附件 (

emailitem.Attachments.Add
)。

© www.soinside.com 2019 - 2024. All rights reserved.