Excel VBA Add graphic signature block to automated email.

NormThib

New Member
Joined
Apr 24, 2021
Messages
3
Office Version
  1. 365
Platform
  1. Windows
I'm trying to add a graphic signature block to an email I create with VBA from Excel data.
I build the body text of the email into a string (MyMsg) pulling various items from my worksheet. I use several vbCrLf to format the text body the way I want it, as shown below:

Hello fellow Toastmaster. Thanks for attending District 53 Club Officer Training. Your club(s) will get credit for your role(s) being trained, as listed below.

Officer Name: FirstName Joe Shmoe
MembID: 12345678
Email: JoeShmoe@isp.com
Train Date: 12/9/2023
Attendance Duration: 146 min

Your training completion has been posted at Toastmasters International and the D53 website. It will take a few days to cascade down to the DCP dashboard.


My original email macro without the graphic sig block works just fine. That is, the email body comes out formatted as illustrated above. Here's the original code:

Dim OutApp As Object
Dim OutMail As Object
Dim strbody As String
Set OutApp = CreateObject("Outlook.Application")
Set OutMail = OutApp.CreateItem(0)
strbody = MyMsg
On Error Resume Next
With OutMail
.To = EmailAddr
.Subject = "Your Toastmasters Officer Training Confirmation"
.Body = strbody
.display
End With
On Error GoTo 0
Set OutMail = Nothing
Set OutApp = Nothing


I tried to add the graphic sig block with the additional lines below.
Dim OutApp As Object
Dim OutMail As Object
Dim strbody As String
Set OutApp = CreateObject("Outlook.Application")
Set OutMail = OutApp.CreateItem(0)
strbody = MyMsg
On Error Resume Next
With OutMail
.To = EmailAddr
.Subject = "Your Toastmasters Officer Training Confirmation"
.Body = strbody
' Trying to add graphic sig block, but it eliminates the strbody formatting.

.Attachments.Add "D:\ThibSig.JPG", olByValue, 0
.HTMLBody = strbody & vbNewLine & "<BODY><IMG src=""cid:ThibSig.JPG"" width=300> </BODY>"

'.Send
.display
End With
On Error GoTo 0
Set OutMail = Nothing
Set OutApp = Nothing


This adds my signature graphic OK, but the email comes out looking like the below, all the vbCrLf are gone and the body text is lumped together as one paragraph.

Hello fellow Toastmaster. Thanks for attending District 53 Club Officer Training. Your club(s) will get credit for your role(s) being trained, as listed below. Officer Name: Joe Shmoe MembID: 12345678 Email: JoeShmoe@isp.com Train Date: 12/9/2023 Attendance Duration: 146 min Your training completion has been posted at Toastmasters International and the D53 website. It will take a few days to cascade down to the DCP dashboard.
1704121998667.png


I don't know HTML at all, and that's probably the source of my problem. Can you suggest how to fix this?
 

Excel Facts

Can you AutoAverage in Excel?
There is a drop-down next to the AutoSum symbol. Open the drop-down to choose AVERAGE, COUNT, MAX, or MIN
Try it like this...

VBA Code:
Sub test()

    Dim OutApp As Object
    Dim OutMail As Object
    Dim EmailAddr As String
    Dim strHTMLBody As String
   
    Set OutApp = CreateObject("Outlook.Application")
    Set OutMail = OutApp.CreateItem(0)
   
    EmailAddr = "example@isp.com"
   
    strHTMLBody = "<p>Hello fellow Toastmaster. Thanks for attending District 53 Club Officer Training. Your club(s) will get credit for your role(s) being trained, as listed below.</p>" & _
                        "<p>Officer Name: FirstName Joe Shmoe<br>" & _
                            "MembID: 12345678<br>" & _
                            "Email: JoeShmoe@isp.com<br>" & _
                            "Train Date: 12/9/2023<br>" & _
                            "Attendance Duration: 146 min</p>" & _
                    "<p>Your training completion has been posted at Toastmasters International and the D53 website. It will take a few days to cascade down to the DCP dashboard.</p>"

    With OutMail
        .To = EmailAddr
        .Subject = "Your Toastmasters Officer Training Confirmation"
        .Attachments.Add "D:\ThibSig.JPG", olByValue, 0
        .HTMLBody = strHTMLBody & "<img src=""cid:ThibSig.JPG"" width=300>"
        '.Send
        .Display
    End With
   
    Set OutMail = Nothing
    Set OutApp = Nothing

End Sub

Hope this helps!
 
Last edited:
Upvote 0
Solution
Thanks! My code was actually more involved than the sample I provided, but I was able to adapt your suggestions to make it work. Very much appreciated!
 
Upvote 0

Forum statistics

Threads
1,215,069
Messages
6,122,959
Members
449,096
Latest member
Anshu121

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top