保留HTMLbody的原始段落间距

在这里输入图像说明 Sub ColdEmail()

Dim OutLookApp As Object Dim OutLookMailItem As Object Dim lastrow As Long Dim iCounter As Long Dim MailDest As String Dim subj As String Dim bod As String Dim ws As Worksheet Dim signature As String lastrow = ThisWorkbook.Worksheets("Prospects").Cells(Rows.Count, "D").End(xlUp).Row 'change worksheet For iCounter = 2 To lastrow Set OutLookApp = CreateObject("Outlook.application") Set OutLookMailItem = OutLookApp.CreateItem(0) signature = Environ("appdata") & "\Microsoft\Signatures\" If Dir(signature, vbDirectory) <> vbNullString Then signature = signature & Dir$(signature & "*.htm") Else: signature = "" End If signature = CreateObject("Scripting.FileSystemObject").GetFile(signature).OpenAsTextStream(1, -2).ReadAll With OutLookMailItem subj = "" MailDest = "" bod = "" If Cells(iCounter, 13) = "*" Then subj = Cells(iCounter, 14).Value MailDest = Cells(iCounter, 7).Value bod = Cells(iCounter, 16).Value .BCC = MailDest .Subject = subj .HTMLBody = bod & signature .Send End If End With Next iCounter End Sub 

上面的代码自动将电子邮件发送到一列电子邮件地址,并从Excel中的列中获取正文段落。

我希望我的消息在Outlook中包含我的默认签名,所以我将我的代码更改为HTMLbody。

发送的电子邮件不保留原始段落间距:

 line 1 line 2 line 3 

现在看起来像这样: line1 line2 line3

我会回应斯科特·霍尔茨曼的build议来阅读HTML。 每当我需要在电子邮件中进行HTML格式化时,我发现<br>是最直接的select。 使用一个<br>将文本移动到下一行。 要创build空白空间(如段落之间的空行),请使用<br><br>

你可以把这个权利放在你的文本所在的单元格中。 方括号将标记为HTML,并将在电子邮件中呈现为中断而不是可读文本。

换句话说: Thanks,<br> Cthulhu在你的excel单元格中的Thanks,<br> Cthulhu ,将渲染为
“谢谢,
邪神”
在你的电子邮件。

它会帮助你阅读编码的HTML 。

现在,你可以这样做:

要加载默认签名(已在Outlook中设置),您可以执行以下操作(并取消您的代码以获取签名):

 With OutLookMailItem .Display signature = .HTMLBody .... 

要格式化HTML的身体,你可以做这样的事情:

 'change font info as needed bod = "<BODY style=font-size:12pt font-family:Times New Roman font-color:blue>" _ & "<p>" & Cells(iCounter, 16).Value & "</p>" _ & "</BODY>" _ & signature