logo
  • Excel Charts
  • About David Aldred & This Blog
  • Consulting & Excel Support

Never Forget an Attachment Again!

June 28, 2013 0 comments Article Advanced, Outlook

How many times have you written an email with the intention of attaching a file, only to send it without actually attaching anything?

Google (and other mail services, I imagine) offer a handy reminder prompt if you try to send an email where you’ve stated there is an attachment, but there is nothing attached.

I liked this, so set out to see if this could be replicated in Outlook. There were a few solutions, but in the end I opted for a VBA based ‘extension’ to do this check.

I based it on some code I found (If I can find the original URL where I found it, I will link to it) and modified & fine-tuned it a bit.

So now, if I go to send such an email, but there is nothing attached, I get a friendly reminder.

 

So how do you do this? You need to add some VBA code to Outlook.

Don’t worry, it’s not as scary as it sounds – it’s pretty straightforward.

From Outlook, hold [ALT]+F11

On the left of this screen, you should see a tree structure. Expand this until you see ‘ThisOutlookSession’ – double click on this

Into the main pain on the right, copy & paste all the code below.

That’s it – it should now work. The next time to quit Outlook, you may be asked if you want to save changes – just say yes.

Option Explicit
Private Sub Application_ItemSend(ByVal Item As Object, Cancel As Boolean)
Dim m As Variant
Dim strBody As String
Dim intIn As Long
Dim intAttachCount As Integer, intStandardAttachCount As Integer
Dim i As Integer
Dim OnlyScreenShots As Boolean
Dim FileName As String
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
'By Setting the below to 'False', it will regard embedded SrceenShots as normal attachements
OnlyScreenShots = True
strBody = LCase(Item.Body)
intIn = InStr(1, strBody, "subject:")
If intIn = 0 Then intIn = Len(strBody)
intIn = InStr(1, Left(strBody, intIn), "attach")
intAttachCount = Item.Attachments.Count
For i = 1 To intAttachCount
FileName = Item.Attachments.Item(i).FileName
Debug.Print FileName
 If OnlyScreenShots <> False Then
 If Len(FileName) = 12 And Left(FileName, 5) = "image" And (Right(FileName, 4) = ".png" Or Right(FileName, 4) = ".jpg") Then
 OnlyScreenShots = True
 Else
 OnlyScreenShots = False
 End If
 End If
Next i
If intIn > 0 And intAttachCount > 0 And OnlyScreenShots = True Then
 m = MsgBox("It appears that you mean to send an attachment," & vbCrLf & "but the ony attachments I can see are Screenshots." & vbCrLf & vbCrLf & "Do you still want to send?", vbQuestion + vbYesNo + vbMsgBoxSetForeground)
 If m = vbNo Then Cancel = True
ElseIf 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

You may need to enable Macros (or decrease the security level from High to Medium, so you’re prompted to allow this macro to run). Some organizations may block all expect Digitally Signed macros. This is a small but usually overcome-able issue, as you can usually self-sign a macro, which would be sufficient. I won’t cover this today, but if someone asks, I’ll do a quick demo.

Related

Tags: Attachments, Outlook, Productivity, VBA

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

How did Microsoft’s Power BI come to lead the Gartner Magic Quadrant?

Meta

  • Register
  • Log in
  • Entries RSS
  • Comments RSS
  • WordPress.org

Categories

Pages

  • Excel Charts
  • About David Aldred & This Blog
  • Consulting & Excel Support

Copyright System Secrets 2025 - Theme by ThemeinProgress