如何在电子邮件VBA Excel中插入链接

时间:2016-10-13 12:12:39

标签: excel vba excel-vba email outlook

我创建了一个宏,在条件填满时向某些人发送电子邮件。但是,在电子邮件正文中,我想插入一个类似于Link而不是 http://blabla.com的链接。

你知道我怎么能做到这一点吗?

链接在我的手机B4上,这是以下代码。

Public Sub email_missing_forecast()

Application.ScreenUpdating = False

'Déclaration des variables

derniereligne = Range("B5000").End(xlUp).Row
Project_number = Cells(1, 2).Value
Project_name = Cells(2, 2).Value
Project_due = Cells(3, 2).Value
lien = Cells(4, 2).Value

Dim Objoutlook As New Outlook.Application
Dim Objectmail

'Condition

For i = 6 To derniereligne

Adresse = Cells(i, "D").Value
Adresse2 = Cells(i, "E").Value
Adresse3 = Cells(i, "F").Value

If Cells(i, "B").Value = "No" Then
    Set Objoutlook = New Outlook.Application
    Set Objectmail = Outlook.createitem(olmailitem)

        With Objectmail
        .To = Adresse & ";" & Adresse2 & ";" & Adresse3
        .Subject = "Bobbi Brown | " & Project_number & " " & Project_name & " | Forecast due " & Project_due
        .Body = "Dear All, " & Chr(10) & Chr(10) & "I kindly remind you that forecasts for program " & Project_number & " " & Project_name & " are due " & Project_due & "." & Chr(10) & Chr(10) & "Please enter your forecast at the link below." & Chr(10) & Chr(10) & lien & Chr(10) & Chr(10) & "Best Regards," & Chr(10) & "Christian Chen"
        .Send

End With
End If
Next i

Application.ScreenUpdating = True

MsgBox "Your e-mails have been sent successfully", , "FIY"
End Sub

1 个答案:

答案 0 :(得分:2)

可以使用HTML正文来获取此信息。请在代码中使用以下行。在Set Objectmail = Outlook.createitem(olmailitem)

下面输入以下这些行
strbody = "Dear All, " & Chr(10) & Chr(10) & "I kindly remind you that forecasts for program " & Project_number & " " & Project_name & " are due " & Project_due & "." & Chr(10) & Chr(10) & "Please enter your forecast at the link below." & Chr(10) & Chr(10) & lien & Chr(10) & Chr(10) & "Best Regards," & Chr(10) & "Christian Chen"

键入以上行后,只需删除

即可

.Body = "Dear All, " & Chr(10) & Chr(10) & "I kindly remind you that forecasts for program " & Project_number & " " & Project_name & " are due " & Project_due & "." & Chr(10) & Chr(10) & "Please enter your forecast at the link below." & Chr(10) & Chr(10) & lien & Chr(10) & Chr(10) & "Best Regards," & Chr(10) & "Christian Chen" 并添加

.HTMLBody = StrBody & "<a href=""" & ActiveSheet.Range("B4") & """ >Name your link</a>"