Thursday, March 1, 2012

How to display alert in outlook express if subject field is empty while sending mail


This is a common mistake every one does while sending mail using outlook. You may feel bad if you send an important mail to the client or to your manager without a subject.

Since Microsoft didn't provide any option to make the subject mandatory or any warning for the empty subject I thought I will do a little research and find out the workaround.

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

Just follow below steps,
1. Of course first we will open outlook
2. Then we will Open Visual basic editor by pressing ALT+F11
3. Then from left pane expand the Project1 until 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

Note: Change the alert as per your interest from above code.

Below is the screen print of the alert which you may be getting,


Now try to send mail without subject from your outlook!!!

My Weblog post

No comments: