如何将列中的超链接插入Outlook电子邮件正文

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

我的列“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 Control\Public\MCR 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链接?

excel vba outlook outlook-vba
1个回答
0
投票

HTMLBody Property合作


示例将显示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)

强制显式声明文件中的所有变量,或允许隐式声明变量。

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