Friday 14 October 2016

Add Secure to the Message Subject before Sending

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

ItemSend

VBA
9 lines
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.
VBA
29 lines
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
VBA
13 lines
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.
VBA
14 lines
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 atTools, Macro Security.
After you test the macro and see that it works, you can either leave macro security set to low orsign 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.)

0 comments:

Post a Comment