我刚开始使用VBA来批量发送电子邮件,但我有一个问题,因为最后一句话和签名之间有多余的一行。
外观如下:
亲爱的先生2,
消息1
消息2
恭喜!
空格
空格
签名
我在不同的论坛上进行了研究,但找不到任何解决方案。
提前感谢您的支持!
这是我正在使用的代码:
Option Explicit
Sub Example()
Dim olApp As Object
Dim olMail As Object
Dim olRecip As Object
Dim olAtmt As Object
Dim iRow As Long
Dim Recip As String
Dim Subject As String
Dim Atmt As String
iRow = 2
Set olApp = CreateObject("Outlook.Application")
Do Until IsEmpty(Cells(iRow, 1))
Recip = Cells(iRow, 1).Value
Subject = Cells(iRow, 3).Value
Atmt = Cells(iRow, 4).Value ' Attachment Path
Set olMail = olApp.CreateItem(0)
With olMail
Set olRecip = .Recipients.Add(Recip)
.Display
.Subject = Subject
.HTMLbody = "<html><body><p>Dear " & Cells(iRow, 2).Value & "," & "<br>" & "<br>" & "message 1" & "<br>" & "<br>" & "message 2" & "<br>" & "<br>" & "Congratulations!" & .HTMLbody
Set olAtmt = .Attachments.Add(Atmt)
olRecip.Resolve
.Save
.Close 1
End With
iRow = iRow + 1
Loop
Set olApp = Nothing
Exit Sub
End Sub'