Body.Replace剥离出html格式

时间:2012-08-29 15:15:52

标签: vba outlook-vba

我有一个电子邮件模板,其中包含html格式和占位符以换出实际值。

在Excel中,我通过Outlook CreateItemFromTemplate方法加载电子邮件。如果此时我保存了电子邮件格式,则会保留。

如果我在身体上执行替换,大部分格式都会被删除:

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

1 个答案:

答案 0 :(得分:5)

感谢此帖:https://stackoverflow.com/a/8473313/569662

我的问题是你必须使用.HTMLBody而不是.Body

.HTMLBody = Replace(.HTMLBody, "#recipient#", "Some other value") 
相关问题