0

I tried all the different solutions to this question: How to add default signature in Outlook.
I did not find that any worked with what I have built.

I'm working with an adaptation of Ron de Bruin's email template worksheet where the email body and recipient are referencing another table.
I am either getting the email body correctly formatted (new-line delimited) with broken signature (containing links and images) OR correct signature but the email body is not properly formatted.

The following shows the signature correctly, but the email body is not properly formatted.

On Error Resume Next

Set olApp = Outlook.Application

Set olMail = olApp.CreateItem(olMailItem)
With olMail
    .display
End With

signature = olMail.HTMLbody

With olMail
    signature = olMail.HTMLbody
    
    .To = StringTo
    .CC = StringCC
    .BCC = StringBCC
    .Subject = Me.Cells(myCell.Row, "I").Value
    .HTMLbody = strHTMLBody & Me.Cells(myCell.Row, "K").Value & signature
Community
  • 1
  • 1

2 Answers2

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." 'Me.TaskID & ": " & Me.TaskTitle
'strBody = Me.Description
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
0

You need to make sure a well-formatted HTML string is assigned to the HTMLBody property. So, if you want to insert anything before the signature you need to find an opening <body> tag and paste your string there right after the <body> tag.

Eugene Astafiev
  • 47,483
  • 3
  • 24
  • 45
  • So if arbitrarily insert the tag like so: '.HTMLbody = strHTMLBody < /b>' I receive a compile error message. This isn't appropriate why? – Deric Babátunde Apr 05 '21 at 12:34
  • Ideally, you need to create a well-formed HTML document with ` your content goes here `. Outlook handles most cases when you assign it to a partially-formed markup, but who knows... – Eugene Astafiev Apr 05 '21 at 14:02