Thursday 6 December 2012

"How to display alert in MS Outlook/Outlook Express if subject field is empty while sending mail"


This is a common mistake everyone does while sending mail using outlook. You feel bad if you send an important mail to the client or higher level manager without subject by mistake. 

Since Microsoft didn't provide any option to make the subject mandatory or any warning for the empty subject it is our responsibility to find out the workaround.

This is a VB code which will display alert when you click on Send Mail button in Outlook if subject field is empty.

Just follow below steps,

1. Ofcourse we have to open the outlook

2. Then we will Open Visual basic editor by pressing ALT+F11

3. Then from left pane expand the Project1 untill you see "ThisOutlookSession"

4. Double Click on "ThisOutlookSession"

5. Now it's the time to copy and paste the below code in the new window opened when you double click on "ThisOutlookSession".

6. Save and Close the window. You are done!



Private Sub Application_ItemSend(ByVal Item As Object, Cancel As Boolean)
            Dim strOutlookSubject As String
            strOutlookSubject = Item.Subject
            If Len(strOutlookSubject) = 0 Then
            Prompt$ = "Are you sure you want to send the Mail without Subject?"
            If MsgBox(Prompt$, vbYesNo + vbQuestion + vbMsgBoxSetForeground, "Subject is empty") = vbNo Then
            Cancel = True
            End If
            End If
        End Sub