Outlook – Add missing subject & missing attachment checker

This happens with most of us while sending out emails in a hurry, we miss the subject or the attachments or even worse miss them both. Here’s a macro which will prevent that.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
Private Sub Application_ItemSend(ByVal Item As Object, Cancel As Boolean)
    Dim strSubject As String
    strSubject = Item.Subject
    If Len(strSubject) = 0 Then
        Prompt$ = "Subject is missing. Are you sure you want to send the email? "
        If MsgBox(Prompt$, vbYesNo + vbQuestion + vbMsgBoxSetForeground, "Subject Missing") = vbNo Then
                Cancel = True
        End If
    End If
    Dim m As Variant
    Dim strBody As String
    Dim intIn As Long
    Dim intNumberOfAttachments As Integer, intZero As Integer
    
    On Error GoTo handleError
    
    intZero = 0
    
    strBody = LCase(Item.Body)
    
    intIn = InStr(1, strBody, "original message")
    
    If intIn = 0 Then intIn = Len(strBody)
    
    intIn = InStr(1, Left(strBody, intIn), "attach")
    If intIn = 0 Then intIn = InStr(1, Left(strBody, Len(strBody)), "pfa")
    
    intNumberOfAttachments = Item.Attachments.count
    
    If intIn > 0 And intNumberOfAttachments <= intZero Then
    
    m = MsgBox("The words attach/pfa were found in this mail," & vbCrLf & "but there is no attachment in this mail." & vbCrLf & vbCrLf & "Do you still want to send?", 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, "Attachment Missing"
    End If


End Sub
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s