Edit subject - and change conversationTopic - using VBA and redemption

Status
Not open for further replies.

AndrewWeb

Member
Outlook version
Outlook 2013 32 bit
Email Account
Exchange Server
Hi all:

My organization has started prepending "[EXTERNAL EMAIL]" to subject lines. Some of the people I correspond with are frustrated by this, especially when replies end up with multiple copies of that string. My goal is to remove that text (at least for certain people).

Using (very helpful) Slipstick resources, (e.g., VBA for incoming emails, removing text from subject lines), I got my VBA working to remove the text in question from the subject. Hooray!

However, I quickly learned that the subject is not the same as conversationTopic, which is what I and others see displayed in the "Subject" column of my outlook folders. Thus, the problem of losing precious space in the subject field was not quite solved. Using more Slipstick and Stackexchange resources (subject + conversation topic, modify conversation topic), I got into Redemption. I don't fully understand Redemption, but I got some code working - mostly (the code, which resides in ThisOutlookSession, follows). And, thus, to my question:

In essence, when I watch emails come in, what I see is the following:
  1. the subject is successfully changed (i.e., when I double click on an email, the subject is simply "Some text"
  2. the conversationTopic is changed (i.e., the subject I see in the folder view changes from "[EXTERNAL EMAIL] Some text" to "Some text")
  3. the conversationTopic reverts to its original value after a second or two (i.e., the subject I see in the folder view goes back to "[EXTERNAL EMAIL] Some text")
This would appear to be related to the notification I get in a message that indicates I have inadvertently made a copy of a message ("This is the most recent version, but you made changes to another copy"). So, does anybody know how I can change the subject *and* conversationTopic *without* creating a copy of the message?

Thanks *very* much in advance,
Andrew

System info: Office 365, Version 1901; Windows 10

Screen capture showing a opened email overlaid on the inbox, with different subject vs. conversationTopic, and the notification that I made a copy:
Untitled.png



Code:

Code:
Option Explicit
Private objNS As Outlook.NameSpace
Private WithEvents objNewMailItems As Outlook.items


Private Sub Application_Startup()
    Dim objMyInbox As Outlook.MAPIFolder
    Set objNS = Application.GetNamespace("MAPI")
    Set objMyInbox = objNS.GetDefaultFolder(olFolderInbox)
    Set objNewMailItems = objMyInbox.items
    
    Set objMyInbox = Nothing
End Sub

Private Sub objNewMailItems_ItemAdd(ByVal Item As Object)
    ' for testing (this MsgBox does indeed pop up)
    MsgBox "Message subject: " & Item.Subject & vbCrLf & "Message sender: " & Item.SenderName & " (" & Item.SenderEmailAddress & ")"
    Debug.Print "conv topic = " & Item.ConversationTopic & ", subject = " & Item.Subject

    ' get a new string for the subject - and hopefully the conversationTopic
    Dim arrStrings As Variant, i As Long
    Dim strNewConversationTopic As String
    arrStrings = Array("[EXTERNAL EMAIL]  ", "RE:", "Re:", "Fw:", "FW:", "etc.")
    For i = 0 To UBound(arrStrings)
        Item.Subject = Trim(Replace(Item.Subject, arr(i), "", , , vbTextCompare))
    Next
    strNewConversationTopic = Item.Subject
    'changing the subject does not change the conversationTopic
    Debug.Print "NEW target conversation topic = " & strNewConversationTopic
        
    'prepare for Redemption
    Dim oRDOSess, oNS, objRDOitem As Object
    Set oRDOSess = CreateObject("Redemption.RDOSession")
    Set oNS = Nothing
    Set oNS = Outlook.GetNamespace("MAPI")
    oNS.Logon
    oRDOSess.MAPIOBJECT = oNS.MAPIOBJECT

    'change conversation topic and save item
    Set objRDOitem = oRDOSess.GetMessageFromID(Item.EntryID, Item.Parent.StoreID)
    objRDOitem.ConversationTopic = strNewConversationTopic
    objRDOitem.Fields("http://schemas.microsoft.com/mapi/proptag/0x00710102") = Null
    objRDOitem.Save
    Set objRDOitem = Nothing
    Item.Save
    Set Item = Nothing

End Sub

Untitled.png


Untitled.png
 
Last edited by a moderator:
especially when replies end up with multiple copies of that string.
On this, the process that adds the tag should check to see if the tag is present, if yes, then don't add it again.

Have you tried saving after you change the subject? Then change the conversation... or only save once:
objRDOitem.Save
Set objRDOitem = Nothing
Item.Save
 
On this, the process that adds the tag should check to see if the tag is present, if yes, then don't add it again.

Right you are... the addition of multiple strings is something that shouldn't happen multiple times. Unfortunately, this appears to be something they're not watching for.

More importantly, thank you. I am up and running now, with an Item.Save after changing the subject, and then objRDOitem.Save after changing the conversationTopic. (I also added a check to see if the prepended text is present in the conversationTopic before changing it.)

Thanks again!
 
Status
Not open for further replies.
Similar threads
Thread starter Title Forum Replies Date
H using VBA to edit subject line Outlook VBA and Custom Forms 0
D Edit Subject (Multiple Accounts) Outlook VBA and Custom Forms 5
R Edit Subject Line of Meeting Invitation? Using Outlook 1
P Edit Subject for every sent message Outlook VBA and Custom Forms 3
J Cannot edit a calendar event received as an invitation Using Outlook 2
E Edit incoming emails to remove a certain sentence added by the "system" Using Outlook 1
B Outlook 2019 Custom Email form - Edit default email form Outlook VBA and Custom Forms 6
L Fetch, edit and forward an email with VBA outlook Outlook VBA and Custom Forms 2
Witzker Outlook 2019 Edit contact from email does not open the user defined contactform Using Outlook 3
T Outlook 2010 Cannot edit Calendar entries in OL 2010. Using Outlook 1
G print attachment straight away; working script edit not working Outlook VBA and Custom Forms 0
A Edit attachment Save and Reply Outlook VBA and Custom Forms 0
F VBA code to dock Styles whenever I write or edit an email Outlook VBA and Custom Forms 0
J Edit auto-complete list in Outlook 2016+/365? Using Outlook 0
J Message search and edit, another way? Outlook VBA and Custom Forms 4
L Wierd Office 365 Contact unable to edit body of random contacts Using Outlook 5
N VBA Script to Open highlighted e-mail and Edit Message Outlook VBA and Custom Forms 5
S Unable to Edit Contact Information in Certain Contact Folders Using Outlook 3
S Outlook.com cannot edit some contacts Using Outlook.com accounts in Outlook 5
B My outlook calendar edit issue Outlook VBA and Custom Forms 0
D VBA to edit body of incoming email and forwarding it Outlook VBA and Custom Forms 11
Diane Poremsky Edit and Save Outlook's Read-Only Attachments Using Outlook 0
P "Edit Message" feature removed in Outlook 2016 for Mac Outlook VBA and Custom Forms 0
snissen Where is "Edit Message" in Outlook 2016? Using Outlook 2
P People/Contact Record gets deleted when I edit it? Using Outlook 3
C Edit/Create Pen Not Working Outlook 2013 Using Outlook 1
X Bulk edit Contact forms Using Outlook 2
A Contact address disappears when opened to edit Using Outlook 5
J Can invitee edit details? Using Outlook 1
G Outlook 2013: Cannot Edit default Holiday Calendar Using Outlook 2
V Custom form won't open for edit Outlook VBA and Custom Forms 3
M Bulk Edit contact notes BCM (Business Contact Manager) 1
M Any way to edit the message field on a 2010 Outlook Form? Using Outlook 3
S OL 2010 shortcut to edit received mail Using Outlook 3
A Cannot edit or open existing contact nor add new ones. BCM (Business Contact Manager) 1
T Exchange 2010: 'could not save item' and 'Unknown error' when edit calendars Exchange Server Administration 1
M Outlook 2003: Cannot edit default Contact Form Using Outlook 11
S how can i edit email address/es from the from field Using Outlook 5
M How to edit a monthly calendar to remove the cover page Using Outlook 1
S How do I edit an attachment in an invite without notifying the attendees? Using Outlook 2
B Notice to user of appt. set by person with permission to edit (Outlook 2003) Using Outlook 7
H Edit email message Using Outlook 7
F Text Format Change - Bulk Edit Contact Notes Using Outlook 2
T Unable to edit Distribution Group membership via Outlook (works via ECP). Exchange Server Administration 7
D How do I edit a macro in Outlook? Outlook VBA and Custom Forms 1
E Currency Edit Control on custom Taskpanes Outlook VBA and Custom Forms 1
E Currency Edit Control on custom Taskpanes Outlook VBA and Custom Forms 1
A edit right pane of mail Outlook VBA and Custom Forms 15
S Correct way to Identify is Mail is opened in Edit Mode Outlook VBA and Custom Forms 1
F Auto changing email subject line in bulk Using Outlook 2

Similar threads

Back
Top