0

I am trying to run a VBScript that searches all the Incoming messages for a specific string on the subject field and replaces it with something else but keeping the rest of the subject content. So far, this is my code but im not getting any results.

Incoming mails subject: [EXTERNAL] abcdfed ghijk lmno

What i need: [*] abcdfed ghijk lmno

Sub RunAScriptRuleRoutine(MyMail As MailItem)
    Dim strID As String
    Dim olNS As Outlook.NameSpace
    Dim msg As Outlook.MailItem
    Dim rply As Outlook.MailItem

    strID = MyMail.EntryID
    Set olNS = Application.GetNamespace("MAPI")
    Set msg = olNS.GetItemFromID(strID)
    ' do stuff with msg, e.g.
    msg.Subject = Replace(msg.Subject, "[EXTERNAL]", "[*]")
    msg.Save

    Set msg = Nothing
    Set olNS = Nothing
End Sub

I will appreciate your help

Gurmanjot Singh
  • 10,224
  • 2
  • 19
  • 43
Andres Mora
  • 1,040
  • 8
  • 16
  • Do you mean to say that in the mail subject, inside the square brackets, there can be any text and you need to replace that text with a *? Or will it always be the word "EXTERNAL"? What problem are you getting? Did you try running the code in debug mode to find the root cause of the issue? – Gurmanjot Singh Jun 14 '17 at 16:14
  • Hello. The word [EXTERNAL] will always arrive with messages. I need to replace it with [*]. I have tried to run the code and i dont get any errors at all. It just doesnt do anything. – Andres Mora Jun 14 '17 at 16:31

1 Answers1

0

Changes to the subject for received messages will only be reflected in the header UI. You also have to change the MailItem.ConversationTopic value, but it is read-only. However, you can use PropertyAccessor.SetProperty("http://schemas.microsoft.com/mapi/proptag/0x0070001F", "New subject") to update it.

Eric Legault
  • 5,706
  • 2
  • 22
  • 38