Quick VBA script: Attachment reminder for Outlook

Many of us, at one time or another, have composed an email in which we've said "I've attached the file you wanted," hit Send -- and then realized that we never attached the file. Oops! This VBA script prevents this from happening.

This Content Component encountered an error

Many of us have at one time or another composed an email in Microsoft Outlook in which we've said "I've attached the file you wanted," 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.

VIEW MEMBER FEEDACK TO THIS MICROSOFT OUTLOOK TIP

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 Microsoft Outlook (which is disabled by default for security reasons).

  1. In Microsoft Outlook, go to Tools -> Macros -> Security and select Medium. You'll be prompted if you want to run macros when you start Microsoft 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 Microsoft 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.

About the author: Serdar Yegulalp is editor of Windows Insight, a newsletter devoted to hints, tips, tricks, news and goodies for all flavors of Windows users.

MEMBER FEEDBACK TO THIS TIP

This is a very useful tip, but can you explain why I get a pop-up message each time the script is executed? It asks me if I want to allow the program access. Is there some way of turning this off?
—Simon P.

******************************************

This warning comes up in different contexts depending on how Outlook is set to run scripts. If you just want to be warned once when you start Outlook, go to Tools -> Macros -> Security and select the "Medium" option (this is part of the instructions in the script).

If you're using something other than Outlook 2003 (which is what I composed the tip with), you might get slightly different behaviors.
—Serdar Yegulalp, tip author

******************************************

I'd like to know why the pop-up message comes behind the test email I'm sending. For users this would just appear as if Outlook had locked!
—Phil H.

******************************************

This hasn't happened on the machines I've worked with, but in the original script's notes, there is this caveat:

"This works best if Outlook is your editor. If Word is your editor, the dialog will pop up behind Word. I believe this is a limitation that cannot be worked around when using VBA."

Are you using Microsoft Word as your email editor?
—Serdar Yegulalp, tip author

******************************************

Microsoft Outlook 2003 will not run the macro, even at low security. I don't think the problem is in the script but in the settings. I am in a network where I have no administrator rights, but I can run macros in other applications easily.

Is there a solution to this?
—Andrei T.

******************************************

One way to get around this would be to sign the macro with the Office 2003 Resource Kit utility Selfcert.exe. This will allow the macro to work on the computer that it has been signed on, but I believe that will only be possible if you are not an admin.

There's a Microsoft article with more information on digitally signing macros in Office 2003.
—Serdar Yegulalp, tip author

******************************************

I have several comments regarding this tip.

—David Horowitz

Do you have comments on this tip? Let us know.

Related information from SearchExchange.com:

  • Reference Center: Exchange scripts and programming
  • Reference Center: Microsoft Outlook tips and resources
  • Please let others know how useful this tip was via the rating scale below. Do you know a helpful Exchange Server, Microsoft Outlook or SharePoint tip, timesaver or workaround? Email the editors to talk about writing for SearchExchange.com.

    This was first published in September 2005

    Dig deeper on Microsoft Exchange Server Scripts and Programming

    Pro+

    Features

    Enjoy the benefits of Pro+ membership, learn more and join.

    0 comments

    Oldest 

    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:

    -ADS BY GOOGLE

    SearchWindowsServer

    SearchEnterpriseDesktop

    SearchCloudComputing

    SearchSQLServer

    Close