0
votes

I have a rule running on incoming mail that moves items with a certain string in their subject line to a folder. It then runs a script to replace part of the subject with something else.

I've put break points in the script to make sure it's running and not a macro security issue. It reads the subject but just won't save the change. I got the script from someone looking for a similar result

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

strID = MyMail.EntryID
Set olNS = Application.GetNamespace("MAPI")
Set olMail = olNS.GetItemFromID(strID)
' do stuff with olMail, e.g.
olMail.Subject = Replace(objMail.Subject, "[Jira]", "something else")
olMail.Save

Set olMail = Nothing
Set olNS = Nothing
End Sub

I know the above is overkill, so I've also checked it with much simpler code but still no success, it just keeps the same subject line that it came in with.

Public Sub Whatever(Mail As Outlook.MailItem)
Mail.Subject = "Hello"
Mail.Save
End Sub

It seems like I'm misunderstanding the MailItem.Save Method but I can't work it out.

I'm using Outlook 2007.

Any Ideas?

2

2 Answers

1
votes

Does not appear to be anything wrong with the second example.

For the first example you are missing Option Explicit

Which would lead you to change objMail to olMail

olMail.Subject = Replace(olMail.Subject, "[Jira]", "something else")
0
votes

The Move method of the MailItem class moves a Microsoft Outlook item to a new folder and returns an Object value that represents the item which has been moved to the designated folder.

So, you need to set the Subject property on the returned object, not the source one.