Want to remove prefixes from email subjects automatically before you send them? Let's do that...
Let's say you're organization decides to add prefixes to inbound emails that are sent from domains other than your own and you want to remove them because you end up with stacked "RE: [EXTERNAL] FW: [EXTERNAL]" added to subjects, breaking the conversation view in Outlook... that's why.
- Windows 10
- Outlook 2016
- Ability to turn on macros in Outlook (you aren't prevented from doing so by an IT policy)
- Make sure you have the developer tab available in Outlook
- Click on 'Developer' in the Outlook ribbon
- Click on 'Visual Basic' to open the Visual Basic editor
- In the Visual Basic editor, on the left side in the 'Project' panel, expand the 'Microsoft Outlook Objects' tree and click on the 'ThisOutlookSession' to open the code editor
- Paste the following code in the code editor:
Option Explicit
Private WithEvents olInboxItems As Items
Private Sub Application_Startup()
Dim objNS As NameSpace
Set objNS = Application.Session
' instantiate objects declared WithEvents
Set olInboxItems = objNS.GetDefaultFolder(olFolderInbox).Items
Set objNS = Nothing
End Sub
Private Sub olInboxItems_ItemAdd(ByVal Item As Object)
On Error Resume Next
RemoveExternal Item
End Sub
Function RemoveExternal(Item As Object)
Dim xSubject As String
If InStr(Item.Subject, "[EXTERNAL]") > 0 Then
xSubject = Replace(Item.Subject, "[EXTERNAL]", "", , 1)
Item.Subject = Trim(xSubject)
' MsgBox "New Subject -> " & Item.Subject, vbOKOnly
Item.Save
End If
End Function- Click 'Save' and exit the Visual Basic editor
Once you have the VBA macro set, it will automatically strip the '[EXTERNAL]' prefix from your email's subject on reciept.
I haven't bothered to deal with more complex cases like nested 'RE: FW:' because email clients handle them differently so this fix works if YOUR organization adds the prefix.
Credits to https://www.extendoffice.com/documents/outlook/5120-outlook-remove-subject-prefixes.html and https://www.slipstick.com/developer/save-attachments-to-the-hard-drive/