Prevent Outlook from sending an email with a blank Subject Line

C

Collector Dave

How can I prevent Outlook 2007 from sending an email with a blank subject line?
Help Please!!
 
M

Michael Bauer [MVP - Outlook]

See the ItemSend event, there you can check the item's Subject property, and
set Cancel=True if you don't want to send.

--
Best regards
Michael Bauer - MVP Outlook

: Outlook Categories? Category Manager Is Your Tool
: VBOffice Reporter for Data Analysis & Reporting
: <http://www.vboffice.net/product.html?pub=6&lang=en>


Am Thu, 5 Nov 2009 13:10:02 -0800 schrieb Collector Dave:
 
J

JP

This event handler checks for blank subjects as well as if you try to
reply to a message with a blank subject.


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

Dim Msg As Outlook.MailItem
Dim subj As String

If TypeName(Item) <> "MailItem" Then Exit Sub

Dim badSubjects() As Variant

badSubjects = Array("RE: ", "FW: ", " ")

Set Msg = Item
subj = Msg.Subject

If IsInArray(badSubjects, subj) Then
If MsgBox("Subject line is empty. Are you sure you want to send
this message?", _
vbQuestion + vbYesNo + vbMsgBoxSetForeground, "No
Subject") = vbNo Then
Cancel = True
End If
End If

End Sub

Function IsInArray(arr() As Variant, valueToCheck As Variant) As
Boolean
' returns true if value is found in array
IsInArray = (UBound(Filter(arr, valueToCheck)) > -1)
End Function
 
V

Vivek

Hi,

Open outlook, press Alt+F11 and press Ctrl+R. Navigate to
"ThisOutlookSession" and paste the below code, save (Ctrl+S) and close VB
editor. close and reopen outlook, enable macros.

Code-------
Private Sub Application_ItemSend(ByVal Item As Object, Cancel As Boolean)
strSubject$ = Item.Subject
If Len(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
End If
End If
End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top