PDA

View Full Version : Including HTML Code in Email Body



Mikeyabosbht
06-16-2022, 08:35 AM
Hi Guys,

I have included some prelim code that should send a HTML email that includes my company signature.

However, it only generates the required signature if I add ".display" method before the .HTML body property within the "With Block".

If I include .send method after .HTML property it strips the email of formatting and I include the .send method after the .HTML body it generates an error message.

I am looking to retain the HTML formatting and the .display method - is this possible, please?

georgiboy
06-17-2022, 01:35 AM
You can have .Display just before the .Send as a simple workaround

Mikeyabosbht
06-17-2022, 06:17 AM
Thank you for your reply, Georgiboy and thank for your help previously with other queries.

When I add the .display method before the .send method the for loop will trigger and output and send one email but then stop and generate a run-time error: "Item has been moved or deleted"

Please let me know if there is an alternative workaround

georgiboy
06-17-2022, 06:45 AM
How about if you add the below line of code under the .Display:

DoEvents

Mikeyabosbht
06-17-2022, 07:03 AM
Darnit - it is still flagging with the same run time error. Thank you for your help. So frustrating as I am really keen to retain the HTML formatting

georgiboy
06-17-2022, 07:30 AM
Google: ron de bruin send email keep signature vba

Have a look at the first link that comes up - he is the master at automating Outlook via excel (IMO)

georgiboy
06-17-2022, 07:47 AM
Here is another example where the signature is captured from the display before it is then sent with the signature:


Sub test()
Dim OApp As Object, OMail As Object, signature As String

Set OApp = CreateObject("Outlook.Application")

For x = 1 To 5
Set OMail = OApp.CreateItem(0)
With OMail
.Display
DoEvents
End With
signature = OMail.HTMLBody
With OMail
.to = "jbloggs@somebusiness.com"
.Subject = "Subject here"
.HTMLBody = "Body text here" & vbNewLine & signature
.Send
End With
Next x

Set OMail = Nothing
Set OApp = Nothing
End Sub

Mikeyabosbht
06-17-2022, 08:16 AM
No. I think you are the master. The sample code you have provided is amazing and works.

Thanks so much!