Я пытаюсь написать документ, который автоматически отправляет электронное письмо определенным людям на определенных условиях. У меня работает код, и я доволен тем, что у меня есть.
Но ....
Когда я изменяю адреса электронной почты на листе в vlookup, код, который у меня больше не получается, выбирает адреса электронной почты.
Есть ли способ исправить это? Заранее спасибо. Код как есть, ниже.
Sub Button1_Click()
Dim OutApp As Object
Dim OutMail As Object
Dim cell As Range
Dim StrBody As String
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) = "true" Then
Set OutMail = OutApp.CreateItem(0)
On Error Resume Next
With OutMail
.To = cell.Value
.Subject = "Urgent Training Notification - Action Required"
.Body = "Dear " & Cells(cell.Row, "A").Value _
& vbNewLine & vbNewLine & _
"Please be aware, " & Cells(cell.Row, "D") & " is required to update the following training:" & vbNewLine & _
" " & vbNewLine & _
Cells(cell.Row, "E") & vbNewLine & _
" " & vbNewLine & _
"This must be rectified within 14 Days." & vbNewLine & _
" " & vbNewLine & _
" " & vbNewLine & _
"Any issues, please escalate as required." & vbNewLine & _
"Many thanks."
.Send 'Or use Display
End With
On Error GoTo 0
Set OutMail = Nothing
End If
Next cell
cleanup:
Set OutApp = Nothing
Application.ScreenUpdating = True
End Sub