Last active
August 29, 2015 14:10
-
-
Save Supm4n/29885a29ccf3981bad18 to your computer and use it in GitHub Desktop.
Forgot attachment detector + cancel option after 3 seconds
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Private Sub Application_ItemSend(ByVal Item As Object, Cancel As Boolean) | |
Dim mailItem As Outlook.mailItem | |
If Not Item.Class = olMail Then Exit Sub | |
Set mailItem = Item | |
Dim attachedWords(0 To 3) As String | |
attachedWords(0) = "attached" | |
attachedWords(1) = "pièce jointe" | |
attachedWords(2) = "piece jointe" | |
attachedWords(3) = "pj" | |
Dim forgot As Boolean | |
forgot = False | |
For i = 0 To UBound(attachedWords) | |
If InStr(LCase(mailItem.Body), attachedWords(i)) > 0 Then | |
forgot = True | |
Exit For | |
End If | |
Next i | |
If forgot = True And mailItem.Attachments.Count = 1 Then | |
'Images in signature are seen as attachments so mailItem.Attachments.Count = 1 | |
If MsgBox("It seems like you forgot to attach a file. Send the email anyway ?", vbYesNo + vbQuestion, "You may forgot to attach a file") = vbNo Then | |
Cancel = True | |
End If | |
End If | |
If Cancel = False Then | |
Dim PauseTime, Start, Finish, TotalTime | |
PauseTime = 3 ' Set duration. | |
Start = Timer ' Set start time. | |
Do While Timer < Start + PauseTime | |
DoEvents ' Yield to other processes. | |
Loop | |
If MsgBox("Do you want to send this email ?", vbYesNo + vbQuestion, "Last chance to cancel") = vbNo Then | |
Cancel = True | |
End If | |
End If | |
End Sub |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment