如何在发送电子邮件时在 VBA 中添加默认电子邮件签名?

时间:2021-04-08 08:14:53

标签: excel vba email

我在添加默认电子邮件签名时遇到了困难,我现在可能正在使用这些代码。我已经花了几天时间。

*Sub sendemail()
Application.DisplayAlerts = True
Applicatioemphasized textn.EnableEvents = True
Dim OutApp As Object
Dim OutMail As Object
Dim EmailBody As Range
Dim sentto, sentcc, subject As String
sentto = ThisWorkbook.Sheets("DISTRO").Range("B2").Value
sentcc = ThisWorkbook.Sheets("DISTRO").Range("B3").Value
subject = ThisWorkbook.Sheets("DISTRO").Range("B4").Value
Set OutApp = CreateObject("Outlook.Application")
Set OutMail = OutApp.CreateItem(0)
On Error Resume Next
ThisWorkbook.Sheets("DISTO").Range("B5").Select
Set EmailBody = ThisWorkbook.Sheets("DISTRO").Range("B5").Value
EmailBody.Copy
With OutMail
.To = sentto
.CC = sentcc
.BCC = ""
.subject = subject
.Body = "Hi," & vbNewLine & vbNewLine & "As discussed please see attached file for your PMT score."
.Display

.Attachments.Add ThisWorkbook.Sheets("DISTRO").Range("B8").Value

End With

End Sub*

1 个答案:

答案 0 :(得分:0)

试试下面的子。子将显示带有默认签名的邮件,您可以根据需要添加正文和附件。

Sub SendMailWithDefaultSign()
On Error GoTo HarunErrHandler
Dim oApp As New Outlook.Application
Dim oEmail As Outlook.MailItem
Dim strAttachment As Variant, strSubject As Variant, strBody As Variant
Dim strEmail As String
Dim fileName As String

strSubject = "VBA code to send mail with default signature."
strEmail = "recipientmail@domain.com"

Set oEmail = oApp.CreateItem(olMailItem)
    
    With oEmail
        .BodyFormat = olFormatHTML
        .Display
        .Recipients.Add strEmail
        .Subject = strSubject
        .HTMLBody = "<b>Hello Everyone,</b><br>" & _
                    "Please cehck the attached file.<br>" & .HTMLBody
        
'        .Attachments.Add fileName
    End With

Exit Sub
HarunErrHandler:
MsgBox "Error :" & Err.Number & ", " & Err.Description, vbInformation, "Error"
End Sub
相关问题