The Wayback Machine - https://web.archive.org/web/20150223012948/http://www.slipstick.com/developer/code-samples/add-secure-message-subject-sending/

Add Secure to the Message Subject before Sending

Last reviewed on February 20, 2015   —  2 comments

Several users asked me how to add secure to the message subject before sending the message.

I need a way to change the subject of an email after I hit send. Specific example: If I have a subject that says "meeting", after I hit send I would like the subject to be automatically changed to "meeting {Secure Message}"

Add Secure to the subject on Send
You can either use an ItemSend macro to add Secure automatically, or use macro to selectively add Secure to the message.

ItemSend

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

Dim strSecure As String
 
strSecure = "Secure " & Item.Subject
Item.Subject = strSecure
     
End Sub

To use ItemSend and add Secure to the subject of some, but not all, messages, you need to use an If statement. If the message meets the condition, Secure is added to the subject.

In this example, we're testing for domains in the address. If a match is found, the subject is edited and sent. To send to all EXCEPT some domains, use
If InStr(LCase(strRecip), arrDomain(n)) = 0 Then.

Private Sub Application_ItemSend(ByVal Item As Object, Cancel As Boolean)
Dim Recipients As Outlook.Recipients
Dim recip, strRecip As String
Dim i, n
Dim arrDomain As Variant
Dim strSecure As String

Set Recipients = Item.Recipients
  For i = Recipients.Count To 1 Step -1
    Set recip = Recipients.Item(i)
      strRecip = recip.Address & " " & strRecip
  Next i

' Set up the array
arrDomain = Array("domain1.com", "domain2.com")
 
' Go through the array and look for a match, then do something
For n = LBound(arrDomain) To UBound(arrDomain)
    If InStr(LCase(strRecip), arrDomain(n)) > 0 Then
        strSecure = "Secure " & Item.Subject
        Item.Subject = strSecure
        Exit Sub
  End If
Next n

End Sub

Macro Button on Ribbon

To use this macro, customize the message ribbon by adding a new button near the existing Send button.

Add Secure to Subject

Sub AddSecure()
Dim Item As MailItem
Set Item = Application.ActiveInspector.CurrentItem()
  
Dim strSecure As String
 
strSecure = "Secure " & Item.Subject
Item.Subject = strSecure
Item.Send
 
End Sub

Add Secure to Reply

Like the previous macro, you'll create a button on the ribbon for this macro. Click the button instead of Reply.

Public Sub SecureReply()
 Dim objApp As Outlook.Application
 Dim objItem As MailItem
 Dim strSecure As String

 Set objApp = Application
 Set objItem = objApp.ActiveExplorer.Selection.Item(1)
 Set Item = objItem.Reply
 
strSecure = "Secure " & Item.Subject
Item.Subject = strSecure
Item.Display
End Sub

How to use Macros

First: You will need macro security set to low during testing.

To check your macro security in Outlook 2010 or 2013, go to File, Options, Trust Center and open Trust Center Settings, and change the Macro Settings. In Outlook 2007 and older, it’s at Tools, Macro Security.

After you test the macro and see that it works, you can either leave macro security set to low or sign the macro.

Open the VBA Editor by pressing Alt+F11 on your keyboard.

To use the macro code in ThisOutlookSession:

  1. Expand Project1 and double click on ThisOutlookSession.
  2. Copy then paste the macro into ThisOutlookSession. (Click within the code, Select All using Ctrl+A, Ctrl+C to copy, Ctrl+V to paste.)

More information as well as screenshots are at How to use the VBA Editor

About Diane Poremsky

Diane Poremsky
A Microsoft Outlook Most Valuable Professional (MVP) since 1999, Diane is the author of several books, including Outlook 2013 Absolute Beginners Book. She also created video training CDs and online training classes for Microsoft Outlook. You can find her helping people online in Outlook Forums as well as in the Microsoft Answers and TechNet forums.

Please post long or more complicated questions at Outlook forums by Slipstick.com.

2 responses to “Add Secure to the Message Subject before Sending”

  1. Dave

    Hi Diane,

    I came across this article and found it rather interesting and applicable to my situation. For me, the idea of having a button that added Secure to a subject line is perfect. I've created a quick step to create a message with Secure in the subject line but that doesn't work with replies. I like the Macro referenced above except for the fact that it immediately sends the email. It seems that it could be a good fit with a little tweaking. Basically, I'd like it to act like the Reply button. So, highlight the message, click the macro button. It adds Secure to the subject line and opens the message like Reply does. I suppose the ultimate solution would be something that would either create a New message with Secure in the subject or Reply to a message and add Secure to the subject line.

    Thanks,
    Dave

Leave a Reply

If the Post Comment button disappears, press your Tab key.

This site uses XenWord.