在源文件中,我在Col A中有收件人“名称”,在Col B中有收件人“电子邮件地址”。
如果B列中的地址无效(例如拼写错误或不正确的“空格”),或者跳过整个循环,我想跳过A列中的人。
Sub EmailSend()
Dim OutApp As Object
Dim OutMail As Object
Dim cell As Range
strGreeting = "<p style='font-family:calibri;font-size:13'>Dear " & Range("A1").Value
strBody = "<p>Sample Body.</p>"
Application.ScreenUpdating = False
Set OutApp = CreateObject("Outlook.Application")
On Error GoTo cleanup
For Each cell In Columns("B").Cells.SpecialCells(xlCellTypeConstants)
If cell.Value Like "?*@?*.?*" And _
LCase(Cells(cell.Row, "C").Value) = "yes" Then
Set OutMail = OutApp.CreateItem(0)
On Error Resume Next
With OutMail
.To = cell.Value
.cc = ""
.Subject = "Meeting request"
.BodyFormat = olFormatHTML
.HTMLbody = strGreeting & strBody
.Display
.Send
End With
On Error GoTo 0
Set OutMail = Nothing
End If
Next cell
cleanup:
Set OutApp = Nothing
Application.ScreenUpdating = True
End Sub