|
Dan Evans' Attachment Checker for
Outlook
A common problem with emails is
that people forget to attach the attachments
they meant to send. This is really annoying for both senders & receivers.
This
script solves the problem.
This is a VBA (Visual Basic for Applications) script is designed to be used with
Outlook 2000, 2002, 2003 or 2007. After you
click the "send" button, the script searches the text of the email to
see if it
contains the word "attach" (or indeed "attached",
"attachment" etc), but doesn't
have an attachment. If this is the case, it asks you if you really wanted to
send it.

|
|
Installation of script There are two ways to install the script.
Both of these methods are relatively easy. They may seem long because I
have spelled out both of them in full detail.
Method 1 is simplest in most cases. However, it
should NOT be used if:
a) You have existing Outlook macros installed, as it will overwrite them.
or
b) You are paranoid about security and think that I'm trying to spread viruses
via a downloadable VbaProject.OTM file (I'm not honestly but it's fair enough
for you to be cautious!)
... In either of these cases you should probably follow method 2 instead
of method 1.
I am grateful for the help of Adam Knight-Markiegi (Birmingham, UK) for
prompting me to investigate/document method 1, and for assisting with making the
instructions clear for all users.
|
Method 1: The easy way
1. Close Outlook.
2. In "My Computer" under the Tools/Folder Options/View tab, select "Show
hidden files and folders" (assuming it's not selected already).
3. You need to find out what is the "Application Data" folder for Outlook
on your machine. This is the directory that contains a number of files,
including Junk Senders.txt,
Outlook.FAV and
VbaProject.OTM.
The location will usually be:
C:\Windows\Application
Data\Microsoft\Outlook\
or
C:\Documents and Settings\username\Application
Data\Microsoft\Outlook\ (where username
is your username)
... but it's worth checking which of these your machine is using. The
easiest way to do this is just to see which of these folders exists on
your machine (going via "My Computer". Alternatively, you can use the
Windows "search"/"for files and folders" feature to search for
Junk Senders.txt,
Outlook.FAV or
VbaProject.OTM to
find the correct folder.
4. Download this VbaProject.OTM file and put
it in the "Application Data" folder. ie. right-click this link and do
"Save target as...", then select the folder you identified in step (3).
You may get a message saying that VbaProject.OTM already exists and do you
want to replace it... click Yes.
5. Assuming you don't want to show hidden files / folders, you can now
reverse what you did in step (2).
6. Open Outlook.7. You will get a
"Security Warning" box - "ThisOutlookSession contains macros by Dan
Evans... This publisher has not been authenticated and therefore could be
imitated....". Tick the "Always trust macros from this source" box and
then press "Enable Macros". [Note you might get this security warning
midway through step (8) instead].
8. In Outlook, press ALT+F8 to activate the Macro window, then press
cancel.
9. Close Outlook, then re-open Outlook.
10.
That's it! When you forget to attach your attachments, you'll get a warning.
11. IF (and it will only happen with some versions of Outlook / Windows)
you keep getting messages "A program is trying to access email addresses
you have stored in Outlook..." then a
workaround to this is available.
|
Method 2: The alternative, detailed way
1. "Copy" (CTRL+C or Edit/Copy) the script from this shaded box:
Private Sub Application_ItemSend(ByVal Item As Object, Cancel As
Boolean)
' VBA program for Outlook, (c) Dan Evans. dan at danevans.co.uk
' Will check if your outgoing email mentions an attachment, but you've
' forgotten to attach it
' v1.03 of 10/8/04 - Modified to search through subject line as well
as message body
' v1.02 of 16/10/02 - No change to code, but tested works with Outlook
2002 as well as Outlook 2000
' v1.01 of 23/9/01 - OK for "Attach" as well as "attach"
' v1.00 of 21/9/01 - Initial working version
Dim intRes As Integer
Dim strMsg As String
Dim strThismsg As String
Dim intOldmsgstart As Integer
intOldmsgstart = InStr(Item.Body, "-----Original Message-----")
' intOldmsgstart is the location of where old/re/fwd msg starts. Will
be 0 if new msg
If intOldmsgstart = 0 Then
strThismsg = Item.Body + " " + Item.Subject
Else
strThismsg = Left(Item.Body, intOldmsgstart) + " " + Item.Subject
End If
' The above if/then/else will set strThismsg to be the text of this
message only,
' excluding old/fwd/re msg
' IE if the original included message is mentioning an attachment,
ignore that
' Also includes the subject line at the end of the strThismsg string
If InStr(LCase(strThismsg), "attach") > 0 Then
If Item.Attachments.Count = 0 Then
strMsg = "Dan Evans' Attachment Checker:" & Chr(13) & Chr(10) & "Your
message mentions an attachment, but doesn't have one." & Chr(13) &
Chr(10) & "Send the message anyway?"
intRes = MsgBox(strMsg, vbYesNo + vbDefaultButton2 + vbExclamation,
"You forgot the attachment!")
If intRes = vbNo Then
' cancel send
Cancel = True
End If
End If
End If
End Sub
|
[Note: Alternatively, you can use the
modified version
from Leonard Slingerland, which has an array of words rather than just one
word].
2. In Outlook, go to Tools/Macro/Visual Basic Editor. This will load up
the Visual Basic Editor window.
3. On the left, you will see a little tree diagram. Click the
Project1/Microsoft Outlook Object/ThisOutlookSession one, then paste (CTRL+V
or Edit/Paste) the code into the blank window that appears.
4. Do Debug/Compile Project 1. Click the disc button to save the code.
5. Exit the Visual Basic Editor. Then close Outlook too (if it asks if you
want to save the code, say yes).
6. Look in C:\Program Files\Microsoft Office\Office
(or C:\Program Files\Microsoft Office\Office10), and there should be a
program called selfcert.exe. If it's not there, then that's not a massive
surprise, since it's not a standard program installed in the Office
installation. To get it you can either:
a) Install it from the MS Office CD (this is the "proper" way). Details of
how to do this are available at
http://support.microsoft.com/support/kb/articles/Q217/2/21.ASP
... or ...
b) Download selfcert from here (zip file), and unzip the
contents into the C:\Program Files\Microsoft Office\Office
(or C:\Program Files\Microsoft Office\Office10) directory.
Strictly speaking I shouldn't be making this download available for
copyright reasons... but since you are unlikely to want to use it unless
you have bought Office anyway, hopefully Microsoft aren't going to
complain! If they do, I will of course withdraw this download if they
request me to do so.
7. Run the selfcert.exe program (just double click it). Type in "Dan
Evans" in the "Your Name" box, then press OK. It will say it has
successfully created a certificate for Dan Evans. Press OK to that.
8. Restart Outlook. If it gives you a security warning about macros, click
"enable macros", ticking the "always trust macros from this
source" box.
9. In Outlook, go to Tools/Macro/Visual Basic.
10. Choose Tools/Digital Signature, then click Choose to sign your project
with the new "Dan Evans" certificate.
11. Save the project, exit Visual Basic, exit Outlook (if it asks if you
want to save the code, say yes).
12. Restart Outlook. It will ask if you want to trust the certificate.
Click the
"don't ask this again" box, then click yes.
13.
That's it! When you forget to attach your attachments, you'll get a warning.
14. IF (and it will only happen with some versions of Outlook / Windows)
you keep getting messages "A program is trying to access email addresses
you have stored in Outlook..." then a
workaround to this is available.
15. A few people have reported cases where the
warning box 'hides' behind the mail window. I haven't been able to
replicate the problem myself, but one user has confirmed that the
following solution fixes the problem. Modify one line in the code,
adding the bit shown here in red:
intRes = MsgBox(strMsg, vbYesNo +
vbDefaultButton2 + vbExclamation + vbSystemModal,
"You forgot the attachment!")
|