The Essential Outlook Script
There are three things other people tend to do in their email that really annoy me. I haven’t found out how to detect and prevent an inappropriate “Reply-All” yet, but the other two, I have a handle on. This is how I put a stop to Blank Subjects and Missing Attachments in MS Outlook.
First, let met me give props to Google and every other VBA coder on the Internet. You can easily find this, or pieces of it, if you look for it. And are willing to glue it together as I have. Hopefully, I can save you a little trouble.
Here’s the process:
1. Open your Outlook.
2. Press Alt+F11. This opens the Visual Basic editor.
3. On the Left Pane, one can see “Microsoft Outlook Objects” or “Project1″, expand this. Now one can see the “ThisOutLookSession”.
4. Double click on “ThisOutLookSession”. It will open up a code pane.
5. Copy and Paste the following code in the right pane.(“Code” Pane)
Private Sub Application_ItemSend(ByVal Item As Object, Cancel As Boolean)
' Will check if your outgoing email mentions an attachment, but you've
' forgotten to attach it. Will also check for blank subject
Dim intRes As Integer
Dim strMsg As String
Dim strThismsg As String
Dim intOldmsgstart As Integer
Dim strSubject As String
strSubject = Item.Subject
If Len(Trim(strSubject)) = 0 Then
Prompt$ = "Subject is Empty. Are you sure you want to send the Mail?"
If MsgBox(Prompt$, vbYesNo + vbQuestion + vbMsgBoxSetForeground, "Check for Subject") = vbNo Then
' cancel send
Cancel = True
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 + " " + strSubject
strThismsg = Left(Item.Body, intOldmsgstart) + " " + strSubject
' The above if/then/else will set strThismsg to be the text of this message only,
' excluding old/fwd/re msg
' exclude the signature block, which often contains the word attach
strSigBlock = "The first words of your signature block go here"
This is one of my additions. Most companies now include some non-enforceable legalese in their signature template that mention attachments. Since this is usually at the end, we can safely exclude anything after the signature to prevent 100% false positives on every email you send.
intSigBlock = InStr(strThismsg, strSigBlock)
strThismsg = Left(strThismsg, intSigBlock)
If InStr(LCase(strThismsg), "attach") > 0 Then
If Item.Attachments.Count = 0 Then
strMsg = "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
6. File | Save "Project1" or whatever
7. You may need to go into Tools, Macro, Security and enable some level of macro usage. You may also need to close Outlook and reload it.
If this doesn’t seem to do anything, the most likely cause is a permissions issue. Microsoft has found religion on macro security and it seems like there are more and more places you need to enable macros to allow something like this to work. Choose a level you feel comfortable with (mine is set for "Warning for all macros"), and it should work fine.