receivedToday = (DateValue(mail.ReceivedTime) = targetDate)
Dim targetDate
If Weekday(Date, vbMonday) = 1 Then
targetDate = DateAdd("d", -3, Date) ' Monday → Friday
Else
targetDate = DateAdd("d", -1, Date) ' Other days → yesterday
End If
For i = items.Count To 1 Step -1
If TypeName(items(i)) = "MailItem" Then
Set mail = items(i)
subjectMatch = InStr(1, mail.Subject, "BCVV", vbTextCompare) > 0
receivedToday = (DateValue(mail.ReceivedTime) = targetDate)
If subjectMatch And receivedToday Then
' Download attachments
If mail.Attachments.Count > 0 Then
For Each attachment In mail.Attachments
attachment.SaveAsFile savePath & attachment.FileName
Next
End If
' Mark as read
mail.UnRead = False
' Move to Completed folder
mail.Move completedFolder
mailCount = mailCount + 1
End If
End If
Next
No comments:
Post a Comment