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.

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 ...


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



RELATED CONTENT
Outlook and Outlook Web Access Tips
Block Web beacons and protect OWA users from spam
Outlook 2007 shut-down problems and fixes
OWA 2007 configuration tricks to boost performance
Pros and cons of Outlook 2007's storage engine redesign
Lock down direct file access and protect OWA users
Simplify an OWA URL on Windows Server 2008
Windows Mobile 6.5 touts Internet Explorer, OWA improvements
Custom error message redirects OWA users
When OWA's default configurations aren't good enough
Save time typing Outlook 2007 messages with Quick Parts

Microsoft Exchange Server Scripts and Programming
Removing old disclaimers from Exchange Server 2003
How to run Exchange Management Shell cmdlets in Exchange Server 2007
Automate complex Exchange 2007 Management Shell tasks via scripting
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

Microsoft Outlook
Microsoft Outlook and SharePoint interoperability considerations
Outlook 2007 shut-down problems and fixes
Microsoft Outlook and SharePoint calendar dos and don'ts
Free tools facilitate large-scale Outlook and SharePoint integrations
Exchange Mailbag: POP3 settings and Outlook issues
Pros and cons of Outlook 2007's storage engine redesign
Fix Outlook 2007 and SharePoint synchronization breaks
Email issues after configuring hosted Exchange server on laptop
Avoid Outlook 2007 performance issues during repairs
A behind-the-scenes look at Outlook 2007 and SharePoint integration
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


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:

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




    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.



    Email Server Solutions: Exchange 2007, Exchange 2003, Exchange 2000, SharePoint
    HomeNewsTopicsITKnowledge ExchangeTipsAsk the ExpertsMultimediaWhite PapersIT Downloads
    About Us  |  Contact Us  |  For Advertisers  |  For Business Partners  |  Site Index  |  RSS
    SEARCH 
    TechTarget provides technology professionals with the information they need to perform their jobs - from developing strategy, to making cost-effective purchase decisions and managing their organizations' technology projects - with its network of technology-specific websites, events and online magazines.

    TechTarget Corporate Web Site  |  Media Kits  |  Site Map




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