Outlook Attachment Reminder Macro

by Jason Green on August 27, 2010 · 9 comments

How many times have you written an email about “the attached file” only to forget to attach the file before hitting send? If you follow the instructions in this post, that’ll never happen again!

We’re going to add a VBA macro to Microsoft Outlook that searches your email for the text “attach” when you click “send”. If it finds that string of text (ie. attached, attachment…) it will check to see if you actually attached a file. If there’s no file attached, you’ll be prompted with a message box. Then, you can either continue without attaching anything, or you can stop the email from sending so you can include your file. Yes, it’s that simple.

*Note: This will not work in Outlook Express as it doesn’t support macros.


How to set it up:

1. Open Outlook.
2. Press Alt+F11 : This will open the Visual Basic editor.
3. Expand the project until you find “ThisOutlookSession” and select it.
4. Copy the code below into the Visual Basic code window.
5. Save.

Now to test:
6. Close & Reopen Outlook for good measure.
7. Write an email containing the word attach.
8. Click send. *This is when you should get the pop-up.

*Note: If you have an image in your email signature, that would count as an attachment. Just change “intStandardAttachCount” from 0 to 1.

Private Sub Application_ItemSend(ByVal Item As Object, Cancel As Boolean)
‘ Pops up a reminder if the word “attach” is found but there is no attachment on your email.
Dim m As Variant
Dim strBody As String
Dim intIn As Long
Dim intAttachCount As Integer, intStandardAttachCount As Integer

On Error GoTo handleError

‘Edit the following line if you have a signature on your email that includes images or other files. Make intStandardAttachCount equal the number of files in your signature.
intStandardAttachCount = 0

strBody = LCase(Item.Body)

intIn = InStr(1, strBody, “original message”)

If intIn = 0 Then intIn = Len(strBody)

intIn = InStr(1, Left(strBody, intIn), “attach”)

intAttachCount = Item.Attachments.Count

If intIn > 0 And intAttachCount <= intStandardAttachCount Then

m = MsgBox(“It appears that you mean to send an attachment,” & vbCrLf & “but there is no attachment to this message.” & vbCrLf & vbCrLf & “Do you still want to send?”, vbQuestion + vbYesNo + vbMsgBoxSetForeground)

If m = vbNo Then Cancel = True

End If

handleError:

If Err.Number <> 0 Then
MsgBox “Outlook Attachment Reminder Error: ” & Err.Description, vbExclamation, “Outlook Attachment Reminder Error”
End If

End Sub

Also, LifeHacker has a script for GreaseMonkey that does the same thing for GMail.

Credit for this Outlook macro goes to Mark Bird. I’ve seen this macro a few times on the internets, but I believe he’s the original creator. You may also find some answers to any questions on his site. Thanks Mark!


There you go! Now anytime you mention an attachment in your email, you’ll be sure to have it attached.

{ 9 comments… read them below or add one }

Andrew November 8, 2010 at 12:43 pm

HI Jason,

I was wondering how you might modify the search criteria from just “attach” to include other possible key words (“list”, “file”, etc..)

I’ve been using Mark’s orginal macro for some time and often wondered how this would work.

Thanks!

Reply

Chiranjiv Kumar December 16, 2010 at 7:15 pm

It doesn’t work in office outlook 2007.

Reply

Jason Green December 27, 2010 at 4:36 pm

I’ll have to see if I can update the code for Office 2007 and 2010.

Reply

Melissa M. Miller July 26, 2011 at 12:14 pm

Any word on the code for Outlook 2010.

Reply

Pascal N. December 14, 2011 at 6:14 am

I had issues because of copy-paste :
the quotation mark was modified from ” to “ which doesn’t work.
Simply replace with ” and it works.
Beware : the macro searchs for “original message” text.
I replaced this with some text in my signature (which is automatically put in every email/answer).

But I faced an error message when the attachement is already opened…
I will look at it when I have more time…

Reply

Pascal N. December 14, 2011 at 6:15 am

It seems that the website replaces the simple quotation mark by WORD-like quotation mark…

Manuel March 15, 2011 at 3:03 pm

Hi Jason,

Is there a difference between files that you attach and files (images) attached in body message?

I have to discard files attached in body message or to know when I attach a file that not belong to he message history.

Thanks in advance.

Best Regards.

Manuel

Reply

Hannah Wood October 28, 2011 at 4:39 am

I had this working but it simply stopped. Now I can send emails without attachments and I get no warning pop up. The script is still there in VBA but it seems to no longer have any effect. I ahve tried deleting it, repasting it, resaving it – I have closed and opened Outlook etc. Argh. It was SUCH a great little helper and now its gone :(

Reply

daem0n January 12, 2012 at 11:55 am

Samehere, I wonder if an update broke it?
I have the code in there and it was working, and get the same results as Hannah Wood.

Reply

Leave a Comment

Previous post:

Next post: