【发布时间】:2019-10-21 10:50:41
【问题描述】:
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。
【问题讨论】: