0

Im having a hard time on adding the default email signature when may code im using right now. it already takes me days already.

*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 Answers1

0

Give a try to below sub. The sub will display mail with default signature and you can add body message as well as attachment as per your need.

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
Harun24hr
  • 30,391
  • 4
  • 21
  • 36