vba - Body.Replace 去除 html 格式

标签 vba outlook

我有一个电子邮件模板,它具有 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

最佳答案

感谢这篇文章:https://stackoverflow.com/a/8473313/569662

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

.HTMLBody = Replace(.HTMLBody, "#recipient#", "Some other value") 

关于vba - Body.Replace 去除 html 格式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12181201/

相关文章:

ssl - 从 outlook imap 服务器获取 offlineimap 的正确证书信息

python - 在 Python 中使用 Yagmail 从 Outlook365 发送电子邮件(允许 SMTP 访问)

excel - 将范围复制为图像并粘贴到 Outlook 中(结果小/模糊)

VBA 在关闭的 Excel 中添加新工作表而不打开并添加工作表名称?

excel - 有没有函数可以找到#DIV/0! 的来源?和#NUM!巨大的 Excel 文件中出现错误?

excel - 在两个电子表格上复制和选择性粘贴

python - 使用 python 读取选定 Outlook 电子邮件的内容

excel - 如何在 VBA 中将时间作为变量?

VBA excel : How do I compare a string array to a string?

html - 电子邮件中未显示 ALT 文本 (Outlook)