繁体   English   中英

vba excel使用简介中的带有html链接的父mailenvelope发送电子邮件

[英]vba excel send email using parent mailenvelope with html link in the introduction

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

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

有任何想法吗?

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

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

我发现一些非常相似的代码似乎使用了稍微不同的方法。 也许会起作用。 似乎绕过了您尝试的Mail.Envelope方法。 罗恩·德布鲁因(Ron de Bruin)的页面上。 不幸的是,我无法在当前计算机上对其进行测试,因此希望对您有所帮助。

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM