使用Excel宏在Outlook上附加签名

时间:2018-12-17 13:03:24

标签: excel vba email outlook signature

即使我所有的谷歌搜索告诉我这都行得通,希望我能帮到我,因为我正在拔头发,

我正在尝试创建一个宏来发送来自excel的电子邮件。它可以工作,但是我必须在发送之前手动添加我的签名。不是世界末日,但仍然令人讨厌。

当我尝试添加代码以添加我的默认签名时,它将应用我的签名,但会删除其余部分。...请帮助!

connect(mChkBox, &QCheckBox::stateChanged, this, &TriStateAction::checkBoxStateChanged);

2 个答案:

答案 0 :(得分:0)

您不能简单地连接两个HTML字符串并期望返回有效的HTML字符串。两者必须合并。

在最简单的情况下,阅读HTMLBody属性(在调用Display之后),搜索"<body"子字符串,找到下一个">"(这将处理带有属性的body元素),然后插入您的HTML字符串(当然没有body元素)。

答案 1 :(得分:0)

根据我的搜索和测试,您可以参考以下代码:

Sub addUpdate_Click()
Dim mailObj As MailItem
Dim emailBody, signature As String
Dim Outlook_App, Outlook_Mail As Object
Dim ToBody As String
Dim CCBody As String
Dim BCCBody As String

Set Outlook_App = CreateObject("Outlook.Application")
Set Outlook_Mail = Outlook_App.CreateItem(0)

ToBody = ThisWorkbook.Sheets("Test").Range("N9")
CCBody = ThisWorkbook.Sheets("Test").Range("N10")
BCCBody = ThisWorkbook.Sheets("Test").Range("N11")

With Outlook_Mail
    .BodyFormat = olFormatHTML
    .Display
End With
signature = Outlook_Mail.HTMLBody

Set mailObj = CreateItem(olMailItem)

emailBody = "<BODY style=font-size:11pt;font-family:Calibri>Hi <br> <br>" & _
        "Your work has been randomly sampled. I have submitted your feedback on the Database. <br> <br>" & _
        "Please can you go in to review and accept your feedback within the next <b>5 working days?</b> <br> <br>" & _
        "<a href= """ & ThisWorkbook.Sheets("Test").Range("N12") & """>User Guide – How to Accept Feedback</a> <br>"

        On Error Resume Next

            With Outlook_Mail

                 .Display
                '.To = ToBody
                '.CC = CCBody
                '.bcc = BCCBody
                .Subject = "Feedback - Action Required"
                .HTMLBody = emailBody & signature

            End With
On Error GoTo 0

        Set Outlook_Mail = Nothing
        Set Outlook_App = Nothing

End Sub

引用来自:

Adding a default signature to outlook email VBA

How to add default signature in Outlook