Мне нужна помощь с кодом для отправки электронных писем только один раз в день.
Когда файл открыт, код устанавливается для автоматической отправки электронных писем и основывается на дате выполнения.Однако этот файл можно открыть несколько раз в течение дня.Мне нужно, чтобы он отправлял электронное письмо только один раз в день (первый раз, когда файл открывается), но я не могу понять, как правильно его кодировать.
For i = 2 To lRow
If Cells(i, 8).Value <> "Completed" Then
If Cells(i, 2) <> "" Then
toDate = Replace(Cells(i, 5), ".", "/")
If Left(Cells(i, 18), 5) <> "Mail" And toDate - Date <= 7 Then
Set OutApp = CreateObject("Outlook.Application")
Set OutMail = OutApp.CreateItem(0)
toList = Cells(i, 7)
eSubject = "ACTION ITEM - " & Cells(i, 3) & " is due on " & Cells(i, 5)
eBody = "NOTICE for " & Cells(i, 6) & vbCrLf & vbCrLf & "This is a reminder that you have task(s) that are due or ones that are past due. Please complete your tasks as soon as possible, then notify the Quality Administrator when the task is complete."
On Error Resume Next
With OutMail
.To = toList
.CC = ""
.BCC = ""
.Subject = eSubject
.Body = eBody
.bodyformat = 1
'.Display
.Send
End With
On Error GoTo 0
Set OutMail = Nothing
Set OutApp = Nothing
Cells(i, 9) = "Mail Sent " & Date + Time
End If
End If
End If
Next i