vba html email

jono19872006

Board Regular
Joined
Mar 13, 2012
Messages
184
Hi

So I have been using some code to autmate the sending of emails which works fine.

However i have been trying to give it a face lift, I currently have pictures in my email signature so want the email to be a html email.

I can get this to work by changing the .body to .HTMLBody.


What I noticed is in the HTML that it doesnt add in new lines </SPAN>eg with the code vbNewLine, I have found the HTML equivalent of "<br>"</SPAN>

However the body of my email is currently a defined cell and the signature with a few lines in between.

What I am struggling with is, if there are new lines in the actual cell's text which is references then they are not replicated in the email.

How can I build into the code a check/replace so that everytime there is the char(10) ie a new line it adds a new line into the HTML email ie "<br>"</SPAN>

?
 

Excel Facts

Round to nearest half hour?
Use =MROUND(A2,"0:30") to round to nearest half hour. Use =CEILING(A2,"0:30") to round to next half hour.
How can I build into the code a check/replace so that everytime there is the char(10) ie a new line it adds a new line into the HTML

Does something like this work for you?

Code:
Dim sBody As String
sBody = Replace(Range("A1").Value, Chr(10), " < br > ") 'Remove the spaces around < and > 
    'email code
    .HTMLBody = sBody
 
Upvote 0

Forum statistics

Threads
1,214,978
Messages
6,122,545
Members
449,089
Latest member
davidcom

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