首页 > 解决方案 > 按原样将文本从 Excel 复制到 Outlook 邮件

问题描述

我正在尝试从 Excel 创建一个自动 Outlook 消息。问题是我当前在 Outlook 消息中的代码文本没有像最初在 Excel 中键入的那样格式化(请参见下面的屏幕截图)。有没有办法让它至少换行(保持换行符)?

因此,如果在 Excel 中输入:

This is text
and it continues
on the next line.

One line break in between also.

它会在 Outlook 消息中显示相同吗?没有像现在这样的班轮...

With olMail
    .To = "office@um.com"
    .Subject = olSubject
    .HTMLBody = "<BODY style=font-size:11pt;font-family:Calibri>" & _
    "MESSAGE" & "<br>" & _
    "Number:" & ThisWorkbook.Worksheets("Other Data").Range("P14").Value & "-" & ThisWorkbook.Worksheets("Other Data").Range("I140").Value & "<br>" & _
    "Include attachments." & "<br>" & _
    "Total:" & ThisWorkbook.Worksheets("Other Data").Range("P38").Value & "<br>" & _
    "Cover notes:" & ThisWorkbook.Worksheets("MAIN").Range("B90").Value & "<br>" & _
    "§§§" & _
    "</BODY>" '& .HTMLBody

我在 Excel 中有这种格式的数据:

在此处输入图像描述

然后它在 Outlook 中显示如下:

在此处输入图像描述

标签: excelvbaoutlook

解决方案


尝试将换行符替换为其 HTML 等效项。因此,例如,替换vbLf<br>...

"Cover notes:" & Replace(ThisWorkbook.Worksheets("MAIN").Range("B90").Value, vbLf, "<br>") & "<br>" & _

推荐阅读