【问题标题】:How to include "mailto" in body of email?如何在电子邮件正文中包含“mailto”?
【发布时间】:2023-02-04 07:22:29
【问题描述】:

我通过 Outlook 发送电子邮件。我试图在电子邮件正文中放置一个电子邮件地址链接,以便点击它并打开一封电子邮件。
例如。 “如果您有任何问题,请通过 ABC 联系我们”,其中“ABC”是代表电子邮件地址的链接,ABC@gmail.com(不是真实地址)。

我知道,从网上搜索,这是语法:

<a href="mailto:ABC@gmail.com\>ABC\</a>

我借用了使用 HTML 在电子邮件正文中格式化消息的代码,并用我想要的替换了一行。
我收到一个编译错误(在这种情况下我认为这实际上是一个语法错误?)。
调试时,“mailto”文本被突出显示。

我的插入:

<a href="mailto:ABC@gmail.com">ABC邮箱</a>

.HTMLBody = "\<HTML\>\<BODY\>\<a href="mailto:ABC@gmail.com"\>ABC mailbox\</a>\</BODY\>\</HTML\>"
Sub SendEmailformattext()
'Update by Extendoffice.com
Dim xRg As Range
Dim xRgEach As Range
Dim xRgVal As String
Dim xAddress As String
Dim OutlookApp As Object
Dim MItem As Object
On Error Resume Next
xAddress = ActiveWindow.RangeSelection.Address
Set xRg = Application.InputBox("Please select email address range", "KuTools For Excel", xAddress, , , , , 8)
If xRg Is Nothing Then Exit Sub
Application.ScreenUpdating = False
Set OutlookApp = CreateObject("Outlook.Application")
Set MItem = OutlookApp.CreateItem(olMailItem)
Set xRg = xRg.SpecialCells(xlCellTypeConstants, xlTextValues)
For Each xRgEach In xRg
    xRgVal = xRgEach.Value
    If xRgVal Like "?*@?*.?\*" Then
        Set MItem = xOutApp.CreateItem(olMailItem)
        With MItem
            .Display
            .To = xRgVal
            .Subject = "Test"
            .HTMLBody = "\<HTML\>\<BODY\>\<a href="mailto:ABC@gmail.com"\>ABC mailbox\</a>\</BODY\>\</HTML\>"
            '.Send
        End With
    End If
Next
Set xMailOut = Nothing

UNCLASSIFIED

Set xOutApp = Nothing
Application.ScreenUpdating = True
End Sub

原始代码有效,所以我知道 mailto 文本是问题所在。

【问题讨论】:

标签: html vba string email hyperlink


【解决方案1】:

如果需要在字符串中使用双引号,请使用 Chr(34) 函数:

.HTMLBody = "<HTML><BODY>**<a href="& Chr(34) & "mailto:ABC@gmail.com" & Chr(34) & ">ABC mailbox</a>**</BODY></HTML>"

【讨论】:

    猜你喜欢
    • 2020-10-08
    • 2014-12-16
    • 2010-11-20
    • 2015-05-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-05-08
    • 2019-10-21
    相关资源
    最近更新 更多