How to Avoid Blank Subject Lines in Outlook 2003-2007


Have you ever received an email with a blank subject line? Have you ever clicked “Send” only to realize you forgot to add a subject? I don’t know about you, but it annoys me when I get a message without a subject. I’ve no idea what the message pertains to, whether it’s a legitimate message or just spam, and can’t tell if it needs my attention right away or if it’s something I can leave until later. It’s even worse when I send a message and forget to fill the subject in. I’ve done it, we probably all have at least once, and I always feel foolish afterward. I can’t help thinking I let the recipients down. This is especially true in a corporate environment where a message without a subject is often perceived as unprofessional.

Apparently I’m not the only one who felt this way about an empty subject line. Microsoft added a new feature (details here under Forgotten subjects) to Outlook 2010 that checks messages for blank subject lines as you send them. On detecting one Outlook displays a dialog-box asking you to confirm that you want to send the message without a subject. [Note: There’s apparently no way to turn this feature off, something that some folks find very annoying.] This is great for the folks with Outlook 2010, but what about those with earlier versions?

Happily there’s a relatively simple solution for them. With a few lines of VBA (Visual Basic for Applications) code we can add the capability to older versions of Outlook. All the code does is trap the event that occurs each time you send an item. It then inspects the subject line to see if it’s empty. If it is, then the code cancels the send and displays a pop-up message asking the sender to enter something in the subject. Once the sender has filled in the subject line Outlook allows the message to go on its way.

This solution will work with any version of Outlook from 2000 through 2007. The code will work in Outlook 2010 too, but it would be redundant since 2010 has a built in blank subject line detector. Who needs two reminders that the subject line is blank? The solution does not work with OWA (Outlook Web Access) which is Outlook in name only. Unlike the full version of Outlook, OWA is a process that runs at the Exchange server and Exchange does not support the use of VBA.

Adding the Code to Outlook.

Outlook 2003 and Earlier.

  1. Start Outlook
  2. Click Tools > Macro > Visual Basic Editor
  3. If not already expanded, expand Microsoft Office Outlook Objects and click on ThisOutlookSession
  4. Copy the code from the Code Snippet box and paste it into the right-hand pane of
  5. Outlook’s VB Editor window
  6. Edit the code as needed. I included comment lines wherever something needs to or can change
  7. Click the diskette icon on the toolbar to save the changes
  8. Close the VB Editor
  9. Click Tools > Macro > Security
  10. Set the Security Level to Medium
  11. Close Outlook
  12. Start Outlook
  13. Outlook will display a dialog-box warning that ThisOutlookSession contains macros and asking if you want to allow them to run. Say yes.

Outlook 2007.

  1. Start Outlook
  2. Press ALT+F11 to open the Visual Basic Editor
  3. If not already expanded, expand Microsoft Office Outlook Objects and click on ThisOutlookSession
  4. Copy the code from the Code Snippet box and paste it into the right-hand pane of Outlook’s VB Editor window
  5. Edit the code as needed. I included comment lines wherever something needs to or can change
  6. Click the diskette icon on the toolbar to save the changes
  7. Close the VB Editor
  8. Click File and select Options
  9. When the Outlook Options dialog appears click Trust Center then click the Trust Center Settings button
  10. Click Macro Settings
  11. Select either of the two bottom settings (i.e. “Notifications for all macros” or “Enable all macros (not recommended; potentially dangerous code can run)”. The choice is up to you. If you select “Notifications”, then you’ll be prompted at times to enable macros. If you pick “Enable all” then there’s a chance that a malicious macro could run. It’s a question of how much risk you want to assume and how many times you want to be prompted (typically once when Outlook first starts).
  12. Click Ok until the dialog-boxes have all closed
  13. Close Outlook
  14. Start Outlook. Outlook will display a dialog-box warning that ThisOutlookSession contains macros and asking if you want to allow them to run. Say yes.
Private Sub Application_ItemSend(ByVal Item As Object, Cancel As Boolean)
    If Item.Subject = "" Then
        'Edit the message and the popup caption on the next line as desired.'
        msgbox "You are not allowed to send an item with a blank subject.  Please enter a subject and send again.", vbCritical + vbOKOnly, "Prevent Blank Subjects"
        Cancel = True
    End If
End Sub

Revisions.

  • Revision 1

This version of the script also prevents sending a reply or forwarding a message with a blank subject line. It requires a little extra code since replying to a message or forwarding one adds “RE:” and “FW:” respectively. The original code would fail to stop those since the subject is no longer actually blank. The code in this version treats a subject line containing just “RE:” or “FW:” as being blank also.

Private Sub Application_ItemSend(ByVal Item As Object, Cancel As Boolean)
    Select Case LCase(Trim(Item.Subject))
        Case "", "re:", "fw:"
            'Edit the message and the popup caption on the next line as desired.'
            MsgBox "You are not allowed to send an item with a blank subject.  Please enter a subject and send again.", vbCritical + vbOKOnly, "Prevent Blank Subjects"
            Cancel = True
    End Select
End Sub

Notes.

Advertisements

35 comments on “How to Avoid Blank Subject Lines in Outlook 2003-2007

  1. Hi David. Thanks for this, especially the revised version for “fw:” & “re:”. I forget to add subjects to some urgent mails at times so this is really helpful.

    • Hi, rschmitty.

      Yes, you can turn macro security off or you can sign the project with a certificate and set macro security to allow signed projects to run.

  2. Pingback: Stripping RE:, FW:, and Fwd: from the Subject Line | TechnicLee

  3. Hi David,

    Do you have a script that would remove RE and FWD from all messages? One of the folks on the legal team here does not want those items in his mail. Many thanks.

    • Hi, Robert.

      I’ can put something together for this. I’m taking some time off for the holidays, so it’ll probably be next week before I have an answer for you.

    • Hi David,

      Many thanks for the reply and Happy New Year. I look forward to your reply when you have the time.

      Regards,

      Robert

    • Hi, Robert.

      Just to clarify, do you want to remove “RE:” and “FW:” on messages being received or those being sent? I can do either or both. The only difference is whether the code checks incoming or outgoing messages.

    • Hello David,

      It would be ideal to have code that could do both, on send and receive. If you could include code for either or, that would be nice as well. Although I would hope that I could figure it out from the main code sample! (BTW, great “handle”!)

      Regards,

      Robert

    • Robert,

      My solution to your question will appear at 8:30 (EDT) this morning. Please let me know if that solves the issue.

      Thanks!

  4. HI, i’m getting blank lines when i run my script in outlook 2003 but the same script when displayed in outlook 2007 doesn’t display these lines

  5. Pingback: FAQ по Microsoft Exchange Server » Как отключить сообщение о пустой теме в Outlook 2010?

  6. is there a way to have something (the same 3 letters) to appear the in subject line of every email i send? with out me having to type those same 3 letters.

    anyone know if and how that can be set up

    • Hi, Terry.

      Sure, that’s simple. Something like this. Change the “XXX” to whatever your three characters are. If you want the characters to appear before the subject, then reverse the order of the items.

      Private Sub Application_ItemSend(ByVal Item As Object, Cancel As Boolean)
          If Item.Class = olMail Then
              Item.Subject = Item.Subject & " XXX"
              Item.Save
          End If
      End Sub
      
    • Hi David, thank you for your response that was really quick, but do know anything about visual basic

    • Terry,

      I assume you mean that you don’t know anything about visual basic. If so, then just follow the instructions I included in the post you commented on. Substitute the code from my reply to your comment in place of the code in the post.

    • lol,ok sorry i busy with other things i didnt take the time to read over eveything, i also i am going to see if there is something that can be setup that when i receive any emails that those emails can insert the 3 letters i need inserted

    • No worries.

      Yes, that’s possible too. It too requires a script. Do you want all messages tagged with the same three characters or only some of them?

    • Terry,

      Sorry to be slow to get back to you. Something like this should get the job done.

      Private Sub Application_NewMailEx(ByVal EntryIDCollection As String)
          'On the next line edit the code as desired
          Const MYCODE = "XXX"
          Dim arrEID As Variant, varEID As Variant, objItm As Object
          arrEID = Split(EntryIDCollection, ",")
          For Each varEID In arrEID
              Set objItm = Session.GetItemFromID(varEID)
              If objItm.Class = olMail Then
                  'Uncomment the next line if you want the code to come at the end of the subject
                  'objItm.Subject = objItm.Subject & " " & MYCODE
                  'Uncomment the next line of you want the code to come before the subject
                  'objItm.Subject = MYCODE & " " & objItm.Subject
                  objItm.Save
              End If
          Next
      End Sub
      
  7. Hello David,

    This is indeed a good thing, and I’m wondering, if you look at eg Mozilla Thunderbird, this also gives you a warning if you state that there’s an attachment, but you were too fast and pressed send anyway.
    Is there also some code to check this ? Also, it should be able to look at more than one word in the mail. hereby I mean that we can send a mail in multiple languages, so the search for certain words in the mail itself should be some sort of array of 3 of 4 words.
    Well, I’m already assuming a lot, no ?
    Best Regards,

    Tom

  8. Just a small point: you may want to check Len(Item.Subject) instead, it is supposed to be a bit faster than a string comparison. But it’s not a deal breaker. Also, you may also want to check for “Re: ” and “FW: ” as those would be indicators that you are replying to an email that came in with a blank subject and you didn’t fix it. I wonder if Outlook 2010 checks for that.

    • Hey, JP.

      Thanks for the suggestions. I’ll consider the idea about checking for RE and FW. I didn’t use Len(Item.Subject) because that would allow the sender to enter one or more spaces which would still be a blank subject line. No, 2010 doesn’t check for RE: or FW:. It appears to be triggered only by a completely empty (i.e. 0 characters) subject line. It must be using Len or something similar since you can defeat the check by putting a space on the line.

    • You would think so, but it doesn’t. Apparently the spaces don’t count as anything during the comparison.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s