Quick VBA script: Attachment reminder for Outlook email

This tip originally appeared on SearchExchange.com, a sister site of SearchCIO-Midmarket.com.

Many of us have at one time or another composed an email in Outlook in which we've said "I've attached the file you wanted,"

    Requires Free Membership to View

hit Send -- and then realized that we never attached the file. Oops!

K.C. Lemson has created a quick Visual Basic for Applications (VBA) script that helps prevent this from happening.

When a message is sent, it checks the body of the message for the word "attach" (either in whole or in part). If there's no attachment, a pop-up dialog box will appear to warn you that there's no attachment in the message.

I have modified the original script slightly so that the check for the word "attach" is case-insensitive, in case you start a sentence with the word (i.e., "Attached is the file you asked for…").

Note that to create the script, you need to first enable macros in Outlook (which is disabled by default for security reasons).

  1. In Outlook, go to Tools -> Macros -> Security and select Medium. You'll be prompted if you want to run macros when you start Outlook.
  2. Go to Tools -> Macros -> Visual Basic Editor.
  3. Double-click on 'This Outlook Session' in the left-hand panel.
  4. Paste the following code into the code window:
  5. Private Sub Application_ItemSend(ByVal Item As Object, Cancel As Boolean)
    Dim lngres As Long
    If InStr(1, UCase(Item.Body), "ATTACH") <> 0 Then
    If Item.Attachments.Count = 0 Then
    lngres = MsgBox("'Attach' in body, but no attachment - send anyway?", _
    vbYesNo + vbDefaultButton2 + vbQuestion, "You asked me to warn you...")
    If lngres = vbNo Then Cancel = True
    End If
    End If
    End Sub

  6. Press F5 to check the code and make sure it's properly compiled.
  7. Close the code editor and restart Outlook. You should be asked on startup if you want to run macros; select Enable Macros.
  8. Send a test message with "attach" somewhere in the body and no attachment to make sure the script works.

Serdar Yegulalp is editor of the Windows Power Users Newsletter. Let us know what you think about this tip; email editor@searchcio-midmarket.com.

This was first published in October 2005

There are Comments. Add yours.

TIP: Want to include a code block in your comment? Use <pre> or <code> tags around the desired text. Ex: <code>insert code</code>

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy
Sort by: OldestNewest

Forgot Password?

No problem! Submit your e-mail address below. We'll send you an email containing your password.

Your password has been sent to:

Disclaimer: Our Tips Exchange is a forum for you to share technical advice and expertise with your peers and to learn from other enterprise IT professionals. TechTarget provides the infrastructure to facilitate this sharing of information. However, we cannot guarantee the accuracy or validity of the material submitted. You agree that your use of the Ask The Expert services and your reliance on any questions, answers, information or other materials received through this Web site is at your own risk.