Outlook Macros - Blank Subject / Missing Attachments


Many times, it happens with us that while sending some important email, we forget to write the “Subject” of the email or forget to attach the required attachment with the email. If you too faced these kinds of problems then here is a macro that you can use with your Outlook Client to get rid of these. I am using this macro from quite long time and it is well tested for my scenario (you are free to enhance it further for your need).
Here are the steps to start using the macro.
Blank Subject
1.       Open your Outlook client
2.       Press Alt+F11. This opens the Visual Basic Editor
3.        On the Left Pane, you should see "Microsoft Office Outlook Objects". Expand this; you should see the “ThisOutLookSession"
4.       Click on "ThisOutLookSession"
5.        Copy and paste the code from given below in the right pane
6.        Save this and close the Visual Basic Editor
7.       Now on it should detect the blank subject line.


                                
                                                                    
                                                                    
                                            
Function SearchForAttachWords(ByVal s As String) As Boolean

    Dim v As Variant
   
    For Each v In Array("attach", "enclos")
   
        If InStr(1, s, v, vbTextCompare) <> 0 Then
       
            SearchForAttachWords = True
           
            Exit Function
           
        End If
       
    Next
   
End Function



Sub ExecuteInsertFileCommand()

    Application.ActiveInspector.CommandBars("Insert").Controls("&File...").Execute
   
End Sub



Private Sub Application_ItemSend(ByVal Item As Object, Cancel As Boolean)

    If Item.Class <> olMail Then Exit Sub

    Dim strSubject As String

    strSubject = Item.Subject
   
    'Check empty subject line...
   
    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 = True
           
            Exit Sub

        End If

    End If
   
    'Check for attached signature...
   
    Dim atmt As Attachment
    Dim hasSignature As Boolean
    hasSignature = False
    For Each atmt In Item.Attachments
        If atmt.FileName = "image001.gif" Then 'Logo gif file
            hasSignature = True
        End If
    Next
   
    'Remove disclaimer from mail-content...
    disclaimerNotice = InStr(Item.Body, "This e-mail communication and any attachments are privileged and confidential and intended only for the use of the recipients named above. If you are not the intended recipient, please do not review, disclose, disseminate, distribute or copy this e-mail and attachments. If you have received this communication in error, please notify the sender immediately by email or telephone.")
    If disclaimerNotice = 0 Then
        mailContent = Item.Subject & ":" & Item.Body
    Else
        mailContent = Left(Item.Body, disclaimerNotice) + " " + Item.Subject
    End If
   
    'Further check for signature...
    If hasSignature Then
        signatureContent = "Mr. XYZ"
        If InStr(mailContent, signatureContent) <> 0 Then
            hasSignature = True
        Else
            hasSignature = False
        End If
    End If
   
    'Check missing attachement...
   
    If SearchForAttachWords(mailContent) Then
        If ((hasSignature And Item.Attachments.Count < 2) Or ((Not hasSignature) And Item.Attachments.Count < 1)) Then
            Prompt$ = "It appears you may have forgotten to specify an attachment." _
                & vbCrLf & vbCrLf & _
                "Are you sure you want to send the Mail?"

            If MsgBox(Prompt, vbYesNo + vbQuestion + vbMsgBoxSetForeground, "No Attachements") = vbNo Then
       
                Cancel = True
               
                Exit Sub

            End If
           
        End If
       
    End If
   
 End Sub



Missing Attachment
For correctly detecting the missing attachment (especially for the case when you keep your signature with your company logo attached with your email), you need to fix the macro appropriately.
1.       Again open the Visual Basic Editor (step 1-4 above)
2.       In the right pane, you should find your existing macro.  Change the name of your company logo file appropriately (like logo1.gif or whatever) in line 63 of the attached code
3.       Review disclaimer-notice string at line 69, must be exactly same as in your signature
4.       Fix line 78 appropriately so that it must be matching with the content of your signature
5.       Save this and close the Visual Basic Editor
6.       Now on it should be correctly be detecting the missing attachment.
Trust the macro
Now if you restart your Outlook client, you “may” (depends on your Outlook’s security-level setting) find your Outlook macros disabled. You can enable them by reducing the security-level to Medium (I will not recommend you to do this) and with this at restart Outlook will pop up Disable/Enable the macros dialog. Alternatively, you can digitally certify your macro. Here are the steps:
1.           Go to Start->All Programs->Microsoft Office -> Microsoft Office Tools ->Digital Certificate for VBA Projects This will open a dialog asking for a name for creating a new digital signature
2.           Give a relevant name and press OK
3.           Go to Outlook and open the Visual Basic Editor
4.           Go to Tools->Digital Signature-> Choose It will open a dialog with a list of available digital signatures. It should show the signature that you have created in step 3 above. Select that and press OK. OK.
5.           Save this and close the Visual Basic Editor
6.           Restart the Outlook
7.           Outlook will pop up a dialog to Disable/Enable the macro. Select Always trust this digital certificate and enable the macro. Next time onward, it will not pop any annoying dialog for enabling the macro.
8.           Done!
I hope that you will find it useful.


Outlook Macros - Blank Subject / Missing Attachments Outlook Macros - Blank Subject / Missing Attachments Reviewed by Sourabh Soni on Friday, October 02, 2009 Rating: 5

No comments

Author Details

Image Link [https://3.bp.blogspot.com/-zo21XIdyPqc/VuTrFfUyPhI/AAAAAAAAAO8/EEWTN73XHUA7aTIjuxuBSN-WGaGkNUymA/s1600/sourabhdots3.jpg] Author Name [Sourabh Soni] Author Description [Technocrat, Problem Solver, Corporate Entrepreneur, Adventure Enthusiast] Facebook Username [sourabh.soni.587] Twitter Username [sourabhs271] GPlus Username [#] Pinterest Username [#] Instagram Username [#] LinkedIn Username [sonisourabh] Youtube Username [sonisourabh] NatGeo Username [271730]