VBA Macro - Adding Outlook HTML signature and Referring specific cell for email body text

jjkh58

New Member
Joined
Apr 21, 2021
Messages
8
Office Version
  1. 365
  2. 2013
  3. 2011
  4. 2010
Platform
  1. Windows
  2. Mobile
  3. Web
Hi guys,

I am trying to add my Outlook signature that has an image with text (i.e. HTML format) and refer specific cell (i.e. .HTMLBody = Range ("B5"). Value) using Macro to return the Outlook Signature with Email body text that is written on cell B5.

I used Ron de Bruin's code (Insert Outlook Signature in mail) but it never seems to be working.

My current code is written below which is the original Ron de Bruin's code but without even making any modifications none of the text is strbody works. The only things that work are the values I specified in ".To", "Subject" and my Outlook Signature (with the correct company logo and text).

So my questions are:

1. How to make the text that I put after "strbody" working
2. Then, I would like to make something like .strbody = Range("B5").Value so that without typing all the email body text directly into Macro, I want Macro to refer to the text that I wrote in cell B5 for the email body.

Please help


Sub Mail_Outlook_With_Signature_Html_1()
' Working in Office 2000-2016
Dim OutApp As Object
Dim OutMail As Object
Dim strbody As String

Set OutApp = CreateObject("Outlook.Application")
Set OutMail = OutApp.CreateItem(0)

strbody = "<H3><B>Dear Customer Ron de Bruin</B></H3>" & _
"Please visit this website to download the new version.<br>" & _
"Let me know if you have problems.<br>" & _
"<A HREF=""Excel for Windows Tips"">Ron's Excel Page</A>" & _
"<br><br><B>Thank you</B>"

On Error Resume Next

With OutMail
.Display
.To = "ron@debruin.nl"
.CC = ""
.BCC = ""
.Subject = "This is the Subject line"
.HTMLBody = strbody & "<br>" & .HTMLBody
.Send
End With

On Error GoTo 0
Set OutMail = Nothing
Set OutApp = Nothing
End Sub
 

Excel Facts

Last used cell?
Press Ctrl+End to move to what Excel thinks is the last used cell.
First, please post code within code tags (vba button on posting toolbar) to maintain indentation and readability
Second, "doesn't work" doesn't help. State what your experience/results are.
Regarding 1) it seems to be working as per attached pic. 2) So refer to the cell as you've shown. If necessary, preface the range with the sheet name.
Also, don't use .Display and then use .Send - especially when you are trying to get something working.
Why are you appending & .HTMLBody to itself? It sure generates a lot of weird xml (?) code that doesn't seem to be necessary. You can see that if you add
Debug.Print .HTMLBody
.HTMLBody = strbody & "<br>" & .HTMLBody



1688929042743.png
 
Upvote 0

Forum statistics

Threads
1,223,879
Messages
6,175,145
Members
452,615
Latest member
bogeys2birdies

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