0

I found the following code to update the subject line.

Sub ChangeSubjectSelection()

Dim selectionIndex As Long
Dim itm As Object

For selectionIndex = 1 To ActiveExplorer.Selection.Count

    Set itm = ActiveExplorer.Selection(selectionIndex)

    If TypeOf itm Is MailItem Then
        itm.Subject = "add value here-" & itm.Subject
        itm.Save
    End If
Next

End Sub
  1. I want this on all outbound emails, but from reading it looks like I have to enable macros, which could be a security risk for inbound emails - yes?
  2. I added a button to the toolbar for outbound emails to fire the VBA, but it changed the ORIGINAL email, not the REPLY email.

I want this on ALL OUTBOUND emails. Forwards, new, replies should have this new word or phrase in the subject- but my current method is updating basically the last email I was sitting on- if I was replying, it would update the original. If I am creating an email it updates the last email I had opened.

Community
  • 1
  • 1
Tina
  • 1
  • 2

2 Answers2

0

So I found a solution to question 2 (Thanks to other code on this site :) this works! - if you see any issue with using this however please let me know). also - I have currently added a button to the quick access toolbar to manually run this to update the Subject line. I would love to have this auto populate on all outbound emails though - so if you have any suggestions I would appreciate it! I'd prefer to not enable all Macros if possible though.. thank you!!

Dim Item As Outlook.MailItem
Dim oInspector As Inspector
Set oInspector = Application.ActiveInspector
Set Item = oInspector.CurrentItem

If InStr(Item.Subject, "New Value -") > 0 Then

Else

    Item.Subject = "New Value -" & Item.Subject

End If
Tina
  • 1
  • 2
  • Application_ItemSend in ThisOutlookSession. See https://stackoverflow.com/questions/35806335/how-can-i-automatically-run-a-macro-when-an-email-is-sent-in-outlook and https://stackoverflow.com/questions/16044846/run-macro-when-email-is-sent – niton Jan 17 '18 at 19:35
0
Private Sub Application_ItemSend(ByVal Item As Object, Cancel As Boolean)
If InStr(Item.Subject, "New Value -") < 1 Then
    Item.Subject = "New Value -" & Item.Subject
End If
End Sub
  • 1
    While this code may answer the question, providing additional context regarding why and/or how this code answers the question improves its long-term value. – Alex Riabov Jul 13 '18 at 17:27