Skip to content

Instantly share code, notes, and snippets.

@Jaskirat
Created January 4, 2010 06:38
Show Gist options
  • Save Jaskirat/268359 to your computer and use it in GitHub Desktop.
Save Jaskirat/268359 to your computer and use it in GitHub Desktop.
MS Outlook forgotten attachment reminder
Private Sub Application_ItemSend(ByVal Item As Object, Cancel As Boolean)
Dim m As Variant
Dim strBody As String
Dim intIn As Long
Dim intAttachCount As Integer, intStandardAttachCount As Integer
On Error GoTo handleError
'Edit the following line if you have a signature on your email that includes images or other files. Make intStandardAttachCount equal the number of files in your signature.
intStandardAttachCount = 0
strBody = LCase(Item.Body)
'Looking for variations of attach
intIn = InStr(1, strBody, "from:")
If intIn = 0 Then intIn = Len(strBody)
intIn = InStr(1, Left(strBody, intIn), "attach")
'Looking for variations of pfa
If intIn = 0 Then
intIn = InStr(1, strBody, "from:")
If intIn = 0 Then intIn = Len(strBody)
intIn = InStr(1, Left(strBody, intIn), "pfa")
End If
'Looking in subject
strSubject = LCase(Item.Subject)
If intIn = 0 Then intIn = InStr(1, strSubject, "attach")
intAttachCount = Item.Attachments.Count
If intIn > 0 And intAttachCount <= intStandardAttachCount Then
m = MsgBox("It appears you have forgotten to attach," & vbCrLf & "Did you mean to send an attachment ? " & vbCrLf & vbCrLf & "I am not sure, so you want to send the mail anyway?", vbQuestion + vbYesNo + vbMsgBoxSetForeground)
If m = vbNo Then Cancel = True
End If
handleError:
If Err.Number <> 0 Then
MsgBox "Outlook Attachment Reminder Error: " & Err.Description, vbExclamation, "Outlook Attachment Reminder Error"
End If
End Sub
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment