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.
I don't know HTML at all, and that's probably the source of my problem. Can you suggest how to fix this?
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.
I don't know HTML at all, and that's probably the source of my problem. Can you suggest how to fix this?