This tip originally appeared on SearchExchange.com, a sister site of SearchSMB.com.
VIEW MEMBER FEEDACK TO THIS TIP
Many of us have at one time or another composed an e-mail in 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 Outlook (which is disabled by default for security reasons).
- In Outlook, go to Tools -> Macros -> Security and select Medium. You'll be prompted if you want to run macros when you start Outlook.
- Go to Tools -> Macros -> Visual Basic Editor.
- Double-click on 'This Outlook Session' in the left-hand panel.
- Paste the following code into the code window:
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
- Press F5 to check the code and make sure it's properly compiled.
- Close the code editor and restart Outlook. You should be asked on startup if you want to run macros; select Enable Macros.
- 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 the Windows Power Users Newsletter.
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
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