Body.Replace strips out html formatting

14,223

Thanks to this post : https://stackoverflow.com/a/8473313/569662

My problem was you have to use .HTMLBody rather than .Body :

.HTMLBody = Replace(.HTMLBody, "#recipient#", "Some other value") 
Share:
14,223
tom redfern
Author by

tom redfern

I spend the time between weekends programming programmers. Want to get in touch? tom.redfern ((at)) Google's popular electronic mail service or https://www.linkedin.com/in/tomredfern/

Updated on June 04, 2022

Comments

  • tom redfern
    tom redfern almost 2 years

    I have an email template which has html formatting and place holders to swap out with real values.

    In Excel I load the email via the Outlook CreateItemFromTemplate method. If at this point I save the email formatting is preserved.

    If I perform a replace on the body most of the formatting is stripped out:

    Set OutApp = CreateObject("Outlook.Application")
    Set OutMail = OutApp.CreateItemFromTemplate("template.oft") ' <- has lots of html formatting
    
    With OutMail
        .Body = Replace(.Body, "#recipient#", "Some other value") ' <- Strips out most formatting!!
        .Save ' <- this works fine without the line above.
    End With