1

I've created a rule in Outlook that automatically moves incoming messages to a folder and runs a script to modify the subject.

This is the rule:

enter image description here

and here is my script:

Public Sub RemoveIrDateTime(Item As Outlook.MailItem)
'Item As Outlook.MailItem

    'stringToMatch = "issued at 11/14/17 6:28 PM"

    Set issuedMsg = New RegExp
    Set priSev = New RegExp
    Set iR = New RegExp

    With issuedMsg
        .Pattern = "issued at \d{1,2}/\d{1,2}/\d\d .+"
        .Global = True
        End With

    With priSev
        '.Pattern = "^P\d/S\d - IR"
        .Pattern = "^.+IR"
        .Global = True
        End With

    Item.Subject = issuedMsg.Replace(Item.Subject, "")
    Item.Subject = priSev.Replace(Item.Subject, "IR")
    'Item.Subject = Left(EmItemail.Subject, 60)

    Item.Save

End Sub

When a matching message arrives, it gets moved to the designated folder, but the subject does not get updated.

However, if I use the 'Manage rules & Alerts' option, and run my rule against the target folder 'Incidents', then the subject of the emails in the folder gets updated as I expect.

Is there a bug in Outlook such that moving the message prevents the script from running? any ideas on how to resolve?

Martijn Pieters
  • 1,048,767
  • 296
  • 4,058
  • 3,343
Steve Ives
  • 7,894
  • 3
  • 24
  • 55
  • Finally came to me with this version of your question. Try .GetInspector to get the mail [Outlook “Run Script” rule not triggering VBA script for incoming messages](https://stackoverflow.com/questions/45661919/outlook-run-script-rule-not-triggering-vba-script-for-incoming-messages) – niton Feb 21 '18 at 12:09
  • @niton Yes - this is a new problem for the solution I am working on, so though it best to start a new question. I've added that line to my script so I'll wait and see what happens. Unfortunately I'd never touched VBA until Monday, so that doesn't help. I'll have another question soon as to why my script can't set the mail item's category. :-) – Steve Ives Feb 21 '18 at 12:26
  • @niton The solution pointed to didn't work for me - I'm pretty sure it added a delay, as when I ran the rule containing the script against a whole folder, Outlook died :-), but it's definitely the folder move that causes the script to not work, as if I take that out the script runs OK. – Steve Ives Feb 22 '18 at 10:05
  • There may be an explanation but in the meantime try ItemAdd code for the Incidents folder. – niton Feb 22 '18 at 17:31
  • "on this computer only" could be the issue as indicated in a comment here [VBA - Change Outlook Subject Line on Receipt Of Email](https://stackoverflow.com/questions/22966209/vba-change-outlook-subject-line-on-receipt-of-email) – niton Feb 24 '18 at 12:16

0 Answers0