You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Word VBA发送带附件邮件时vbNewLine换行失效问题求助

问题原因及解决办法

你遇到的问题根源在于:你用HTMLBody属性设置邮件内容,但vbNewLine是VBA的文本换行符,HTML并不识别它,所以所有内容会挤在一行显示。

HTML里要实现换行,得用HTML专属的标记:

  • 单换行用<br>标签
  • 段落分隔(带间距)用<p>标签

修改后的代码

Sub SendEmail_Example1()

Dim EmailApp As Outlook.Application
Dim FilePath As String
Dim FileName As String
Set EmailApp = New Outlook.Application

Dim EmailItem As Outlook.MailItem
Set EmailItem = EmailApp.CreateItem(olMailItem)

EmailItem.To = "name@xxx.com"
EmailItem.Subject = "Test Email From Word VBA"
' 用HTML标签实现换行和段落间距
EmailItem.HTMLBody = "Hi,<br><br>This is my first email from Word<br><br>Regards,<br>Chris"
FilePath = "https://d.docs.live.net/00f559247767a0d7/Documents/NT/Template/"
'Set Correct Filename
FileName = FilePath & "Test Booking Form.docx"

EmailItem.Attachments.Add FileName

EmailItem.Send

End Sub

如果想要更规范的段落格式(每个部分单独成段,自带上下间距),可以改成用<p>标签:

EmailItem.HTMLBody = "<p>Hi,</p><p>This is my first email from Word</p><p>Regards,<br>Chris</p>"

这样修改后,邮件内容就能按照你期望的格式显示了。

内容的提问来源于stack exchange,提问作者Chris

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.21 04:43:20