Who has never encountered the following problem:
You want to send somebody an email with an attachment. You create the message, hit send and the second you let go of the send button, you think “%$@!%!^, I forgot to attach the file”
One of my colleagues had a possible work around for this problem: prevent outlook from sending messages directly when you hit send, but have outlook send all messages in the outbox every given number of minutes. This way, on average you have some time to figure out you forgot to attach something
I have to say that I did not like this work around that much, so I started looking on the internet what I can find as other means to tackle this problem. I found aBlog with some VBA macros that will give an additional warning when it appears you forgot an attachment while sending the email.
The author of the original article did have one other complaint, and that was that he was getting a security warning every time the macro was run. This can be solved in two ways: you can either set the security level for macros in Outlook to Low (i.e. every macro can be executed, bad bad idea
). The other way is to self-sign your VBA project, for which you can also find instructions on the internet.
One other thing that I did not like about the code as presented on ablog, is that it does not try to be clever about false positives: If I send an email to somebody with the word attach in it, and that person replies to my email, this reply contains the word attach (because of my original message). If you now reply to this reply again, the macro will detect the word “attach” from the original message, and trigger a warning when you try to send the email. I don’t want to be bothered with warning messages if they are most probably not needed, so the macro almost fit my needs, but not 100% yet
To overcome this last problem, I have modified the original code just a little bit. Because I hope that somebody else might have some advantage with this modification, I have put it below:
Option Explicit Private Sub Application_ItemSend(ByVal Item As Object, Cancel As Boolean) If Item.Class = Outlook.olMail Then If Item.Attachments.count = 0 Then If SearchForAttachWords(Item.Body) Then Dim userReply As VBA.VbMsgBoxResult userReply = VBA.MsgBox("It appears you are sending the email without attachments while " & _ "the body/subject contains possible references to an attachment." & _ VBA.vbnewline & "Do you want to send the message without attachments?", _ VBA.vbYesNo + VBA.vbDefaultButton2 + VBA.vbQuestion + VBA.vbSystemModal, _ "Possibly missing attachment...") If userReply = VBA.vbNo Then Cancel = True End If End If End If End If End Sub Function SearchForAttachWords(ByVal s As String) As Boolean Dim positionMailTo As Long positionMailTo = VBA.InStr(1, s, "mailto:", VBA.vbTextCompare) If positionMailTo = 0 Then positionMailTo = VBA.InStr(1, s, "From:", VBA.vbTextCompare) If positionMailTo = 0 Then positionMailTo = VBA.Len(s) End If End If Dim v As Variant For Each v In Array("attach", "enclosed", "bijgevoegd", "bijlage") Dim tempPos As Long tempPos = VBA.InStr(1, s, v, VBA.vbTextCompare) 'Only interested in the keywords when they are before mailto:, 'which would be the original message we are replying to If (tempPos <> 0) And (tempPos < positionMailTo) Then SearchForAttachWords = True Exit Function End If Next End Function
To get everything working, copy the above to your clipboard, fire up outlook and press ALT-F11 to get to the visual basic editor. In the visual basic editor, go to the ThisOutlookSession which can be found under Project1->Microsoft Outlook Objects. After you copied this and you don’t want to be annoyed with security warnings of outlook, please follow the earlier mentioned link regarding signing the project with a self-signed certificate.
Some comments regarding the above code:
- I prefix all functions and values with their respective origin (e.g. VBA.InStr(…), VBA.MsgBox(…), and VBA.vbYesNo, etc ). The reason for this is that at my work, I have outlook 2007 installed on my computer. I have created quite a bunch of macros that are now distributed via copying the VbaProject.otm file. Unfortunately, when other users have outlook 2002 or outlook 2003, they get error messages about things that cannot be found when I do not prefix everything. After the prefixing, there are no problems at all.
- bijgevoegd / bijlage are the dutch words for “attached” and “attachment”. Of course if you want to have the warning trigger on other words, you can put the additional words on this line.
Please let me know if you have any additions to the macro that I did not think of yet, or drop me a note in case the macro has saved you from some embarrassing resend after you just sent a message without attachment

I always enjoy what you have to say, keep up the good work. Do you have a webcam?
Hi Guido, I was unable to get the macro to work. There are no error messages, and I have self-signed the macro. However, when I send a message with the words I put in the array, such as attachment, attached, etc. outlook sends the message without prompting me. Any ideas?
Thanks,
Tijs
Hi Tijs,
which version of outlook do you have installed?
Furthermore, are you sure that you pasted the code into the ThisOutlookSession object? If you paste it somewhere else, it will not work because the ItemSend event will only call the Application_ItemSend procedure in the ThisOutlookSession object.
I am running Outlook 2007, and I checked to be sure the code is in the ThisOutlookSession object. I’ve noticed that it begins working on reply emails, where the original email said the word attachment. So it seems that one of the variables somewhere isn’t being set when a new email is composed, but is being set when a previous email is being replied to. Any ideas?
Unfortunately I don’t know what could cause this particular case of events. What the macro basically does is use the procedure that is called automatically by outlook whenever an email is sent. I don’t know what could cause it to trigger in one case and not trigger in another case.
Hi Guido,
the macro seemed to be working fine the first time, but after restarting Outlook it doesn’t any more. Is there something else I should do?
And thanks by the way. I had the same idea, that is fixing this problem, except I don’t know anything about coding. (I even tried finding a suggestion box at microsoft.com, what was I thinking??) But like always, there is someone else who has thought of it before you, and solved it.
I had the same problem as Peter, would be grateful for the cure!
After following the instructions above i find the code works perfectly. Make sure you save the project and enable the macros with this self-signed signature
I used it yesterday without any problems. I like it so much, I send e-mail intentionally “forgetting” the attachments. But this morning, it just sends my e-mails without reminding me. Is there some secret code that can tell I’m just goofing around?
I did not include any code that determines you are goofing around
I don’t know what could be causing it for you. Have you followed all the steps about self-signing the macro also?
Furthermore, which version of outlook do you have? Does the problem persist after you have opened the macro editor with ALT-F11 ?
Regards,
Guido Diepen
I use Outlook 2003 (SP3).
I hadn’t signed the macro yet, because it ran without problems. At your suggestion I did sign the macro, but in Outlook, the menu Tools-> Macro-> Macros… did not show my macro.
Changing Security Levels to Low, closing Outlook: “Do you want to save Project1.OTM?” Yes. Restarting Outlook, Closing Outlook: “Do you want to save Project1.OTM?” Hmmm, I thought I just did.
It turned out after closing Outlook, there was still an Outlook.exe process running. I killed it, restarted Outlook: “Do you trust the macro of Feike?” Yes, I do!
I put Security Levels back to High and things work fine now
i use u work in my plugin. for extract attachments outlook) mapilab lol)
I use Outlook 2007. Followed all the steps, got prompted about trusting the macro (so it must know it is there). However when I send an email refferring to an attachment that is not there I get nothing. It just sends as per usual.
Any ideas?
@Hannah
Are you absolutely sure that you pasted the code in the ThisOutlookSession object that already existed (i.e. that you did not create it yourself)?
One thing you can try is to put something like:
VBA.MsgBox “Testing”
as the first line of the Application_ItemSend procedure. This should result in a messagebox with every message you send.
But my guess would be that you pasted the code in another module, and not in the ThisOutlookSession object that should always exist.
Kind regards,
Guido Dieepn
If I use this code, then I get the message box prompt come up with the “it appears…” message. That’s as far as I can get it to work. If I put the Item.Attachments.count = 0 code back in i get nothing happening.
The code is pasted into ThisOutlookSession, and has been digitally signed. Just does not appear to work with the full code.
Cheers,
Hannah
Option Explicit
Private Sub Application_ItemSend(ByVal Item As Object, Cancel As Boolean)
If Item.Class = Outlook.olMail Then
Dim userReply As VBA.VbMsgBoxResult
userReply = VBA.MsgBox(“It appears you are sending the email without attachments while ” & _
“the body/subject contains possible references to an attachment.” & _
VBA.vbNewLine & “Do you want to send the message without attachments?”, _
VBA.vbYesNo + VBA.vbDefaultButton2 + VBA.vbQuestion + VBA.vbSystemModal, _
“Possibly missing attachment…”)
If userReply = VBA.vbNo Then
Cancel = True
End If
End If
End Sub
I really don’t know why this code is not executed at all, if anybody has some idea, please post it here.