【问题标题】:vba excel send email using parent mailenvelope with html link in the introductionvba excel在介绍中使用带有html链接的父邮件信封发送电子邮件
【发布时间】:2015-02-20 17:37:30
【问题描述】:

使用 Outlook 将 html 超链接添加到电子邮件正文似乎很简单。 但是,我想在电子表格中发送一系列单元格,并在介绍中发送指向该文件的链接。或者点击电子邮件中创建的图像并链接到文件的简单方法。

我有以下代码,但是 strbody 如果我将介绍指定为 HTMLintroduction,则不允许。

有什么想法吗?

Sub SendMail2()



Dim OutApp As Object
Dim OutMail As Object
Dim strbody As String
'Dim Sendrng As Range

Set Sendrng = Worksheets("Dashboard").Range("A1:Q34")

If ActiveWorkbook.Path <> "" Then
    Set OutApp = CreateObject("Outlook.Application")
    Set OutMail = OutApp.CreateItem(0)

    strbody = "<font size=""3"" face=""Calibri"">" & _
               ActiveWorkbook.Name & "</B> is created.<br>" & _
              "Click on this link to open the file : " & _
              "<A HREF=""file://" & ActiveWorkbook.FullName & _
              """>Link to the file</A>"

With Sendrng

ActiveWorkbook.EnvelopeVisible = True
    With .Parent.MailEnvelope
        .Introduction = strbody


On Error Resume Next
  With ActiveSheet.MailEnvelope.Item
        .To = "ac@uk.com"
        .CC = ""
        .BCC = ""
        .Subject = ActiveWorkbook.Name
        '.HTMLBody = strbody
        .Display   'or use .Send
    End With

    End With

    End With

    On Error GoTo 0

    Set OutMail = Nothing
    Set OutApp = Nothing
Else
    MsgBox "Email not sent."
End If
End Sub

【问题讨论】:

    标签: html vba email excel


    【解决方案1】:

    编辑 - (http://vba-useful.blogspot.com/2014/01/send-html-email-with-embedded-images.html)
    上面的链接详细说明了如何使 jpg 超出范围并在电子邮件中发送。

    我发现一些非常相似的代码似乎使用了稍微不同的方法。也许它会起作用。它似乎绕过了您正在尝试的 Mail.Envelope 方法。来自Ron de Bruin's 页面。不幸的是,我无法在我目前的机器上测试它,所以我希望它有所帮助。

    Sub Make_Outlook_Mail_With_File_Link()
    'For Tips see: http://www.rondebruin.nl/win/winmail/Outlook/tips.htm
    'Working in Excel 2000-2013
        Dim OutApp As Object
        Dim OutMail As Object
        Dim strbody As String
    
        If ActiveWorkbook.Path <> "" Then
            Set OutApp = CreateObject("Outlook.Application")
            Set OutMail = OutApp.CreateItem(0)
    
            strbody = "<font size=""3"" face=""Calibri"">" & _
                      "Colleagues,<br><br>" & _
                      "I want to inform you that the next sales Order :<br><B>" & _
                      ActiveWorkbook.Name & "</B> is created.<br>" & _
                      "Click on this link to open the file : " & _
                      "<A HREF=""file://" & ActiveWorkbook.FullName & _
                      """>Link to the file</A>" & _
                      "<br><br>Regards," & _
                      "<br><br>Account Management</font>"
    
            On Error Resume Next
            With OutMail
                .To = "ron@debruin.nl"
                .CC = ""
                .BCC = ""
                .Subject = ActiveWorkbook.Name
                .HTMLBody = strbody
                .Display   'or use .Send
            End With
            On Error GoTo 0
    
            Set OutMail = Nothing
            Set OutApp = Nothing
        Else
            MsgBox "The ActiveWorkbook does not have a path, Save the file first."
        End If
    End Sub
    

    【讨论】:

    • 这没有达到我的要求。我希望将范围的图像发送给电子邮件收件人并获得该工作簿的链接。因此我必须使用邮件信封。或者有没有办法使范围的图像成为可点击的超链接?
    猜你喜欢
    • 2023-01-19
    • 1970-01-01
    • 1970-01-01
    • 2017-05-23
    • 2012-08-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-01-08
    相关资源
    最近更新 更多