Check for Missing Attachment and Subject in Outlook

Posted: May 9, 2013 by Transformer in General Tips, Outlook, VBA
Tags: ,

We send so many mails everyday that sometimes we forget to attach files or add subject line. Here we have a macro that solves both the issues.It prompts the user if:

  1. subject line is missing or
  2. there are words like enclosedattached and PFA in message body but attachment is missing

To add this macro in your outlook go to Tools -> Macro -> Visual Basic Editor or just press Alt+F11 and paste the macro in ThisOutlookSession.

Subject Line or Attachment Missing_1

VBA Editor in Outlook

Subject Line or Attachment Missing_2


Private Sub Application_ItemSend(ByVal Item As Object, Cancel As Boolean)

    Dim lngAns                  As Long
    Dim varArray                As Variant
    Dim strWordFound            As String

    varArray = Array("PFA", "Attached", "Enclosed")

    For lngCount = LBound(varArray) To UBound(varArray)
        If InStr(1, Item.Body, varArray(lngCount), vbTextCompare) Or InStr(1, Item.Subject, varArray(lngCount), vbTextCompare) Then
            strWordFound = strWordFound & "," & varArray(lngCount)
        End If
    strWordFound = Mid(strWordFound, 2)
    If Len(strWordFound) > 0 And Item.Attachments.Count = 0 Then
        If MsgBox("Found No Attachments but the Word(s): " & _
                        strWordFound & vbTab & vbCr & "Do you want to send the mail anyway?", _
                                vbYesNo + vbQuestion, "Attachment Missing") = vbNo Then Cancel = True
    End If
    If Len(Trim(Item.Subject)) = 0 Then
        If MsgBox("Subject is Empty. Are you sure you want to send the Mail?", _
                    vbYesNo + vbQuestion + vbMsgBoxSetForeground, "Subject Missing") = vbNo Then Cancel = True

    End If

End Sub
  1. […] middle of Times Square in New York.  To help accommodate this thinness—and not burn your lap—Lenovo also throttles down CPU clock speeds to help keep heat under control. […]

Share your thoughts/feedback

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

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

Google+ photo

You are commenting using your Google+ 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 )


Connecting to %s