Home > Microsoft Exchange Tips > Outlook and Outlook Web Access Tips > Quick VBA script: Attachment reminder for Outlook
Exchange Tips:
EMAIL THIS
 TIPS & NEWSLETTERS TOPICS 

OUTLOOK AND OUTLOOK WEB ACCESS TIPS

Quick VBA script: Attachment reminder for Outlook


Serdar Yegulalp
09.19.2005
Rating: -5.00- (out of 5)


Digg This!    StumbleUpon Toolbar StumbleUpon    Bookmark with Delicious Del.icio.us   


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.

    Rate this Tip
    To rate tips, you must be a member of SearchExchange.com.
    Register now to start rating these tips. Log in if you are already a member.


    Submit a Tip




    Digg This!    StumbleUpon Toolbar StumbleUpon    Bookmark with Delicious Del.icio.us   


    RELATED CONTENT
    Outlook and Outlook Web Access Tips
    Free tools keep Microsoft Outlook visible in Windows Vista
    Tool deploys customized Microsoft Outlook 2007 configurations
    Slipstreaming Microsoft Office 2007 deployments
    Use the OWA Admin tool to 'segment' Outlook Web Access 2003 features
    Repairing damaged OWA virtual directories in Exchange Server 2003
    How to access SharePoint sites through Microsoft Outlook
    What makes Microsoft Outlook 2007's Search feature special?
    OWA won't load after applying Exchange 2007 SP1 security patch
    Minimize remote and mobile Outlook Web Access (OWA) security risks
    Uncovering Microsoft Outlook 2007's hidden diagnostic tools

    Microsoft Exchange Server Scripts and Programming
    Exchange event sink scripting error when configuring email disclaimer
    EMS add-on tool generates graphical Exchange Server 2007 reports
    A primer on the Exchange Server 2007 Exchange Management Shell
    How to generate HTML reports with the Exchange Management Shell (EMS)
    Use the Exchange Management Shell Set command to block senders
    How to test Exchange Management Shell commands
    Grant or deny permissions to access a user's Exchange 2007 mailbox
    Control query results with Exchange Management Shell's Format command
    How to use Exchange Management Shell's Filter command
    How to use the Exchange Management Shell command syntax

    Microsoft Outlook
    Free tools keep Microsoft Outlook visible in Windows Vista
    Migrating .PST files to an Exchange Server information store
    Troubleshoot Outlook 2007 error 0X8004010F on Exchange Server 2007
    How to export Global Address List data to Microsoft Office Access
    Revised Outlook out-of-office (OOF) messages don't update in OWA
    Create a group policy to prevent .PST file storage in Exchange 2007
    Microsoft Exchange Server and Outlook email archiving FAQs
    Tool deploys customized Microsoft Outlook 2007 configurations
    Slipstreaming Microsoft Office 2007 deployments
    Does Exchange cached mode work with all versions of Microsoft Outlook?
    Microsoft Outlook Research

    RELATED GLOSSARY TERMS
    Terms from Whatis.com − the technology online dictionary
    application program interface  (SearchExchange.com)
    event sink  (SearchExchange.com)
    synchronous groupware  (SearchExchange.com)

    RELATED RESOURCES
    2020software.com, trial software downloads for accounting software, ERP software, CRM software and business software systems
    Search Bitpipe.com for the latest white papers and business webcasts
    Whatis.com, the online computer dictionary

    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.

    HomeNewsTopicsITKnowledge ExchangeTipsAsk the ExpertsMultimediaWhite PapersIT Downloads
    About Us  |  Contact Us  |  For Advertisers  |  For Business Partners  |  Site Index  |  RSS
    SEARCH 
    TechTarget provides enterprise IT professionals with the information they need to perform their jobs - from developing strategy, to making cost-effective IT purchase decisions and managing their organizations' IT projects - with its network of technology-specific Web sites, events and magazines.

    TechTarget Corporate Web Site  |  Media Kits  |  Reprints  |  Site Map




    All Rights Reserved, Copyright 2004 - 2008, TechTarget | Read our Privacy Policy
      TechTarget - The IT Media ROI Experts