VBA rule + script run on manul testing but not automatically RRS feed

  • Question

  • I have the following VBA script that I have setup along w/ a rule in Outlook 2016. The rule + script works correctly if I go to Rule Wizard and run manually but doesn't trigger when new mail comes in and rules should be running the script. I found various references to similar issue that mentioned I need to change the Trust Center setting so I have changed Macro setting to Enabled all.

    p.s. I think this issue is not related to the code as all but related to how Outlook rule trigger VBA script

    Sub filter(Item As Outlook.MailItem) 
        Set Reg1 = CreateObject("VBScript.RegExp") 
        Reg1.IgnoreCase = True 
        Reg1.Global = True 
        Reg1.Pattern = "foo" 
        If Reg1.Test(Item.Subject) Then 
            strSubject = Item.Subject 
            Item.Subject = strSubject & "bar" 
        End If 
    End Sub 
    Thursday, October 6, 2016 9:59 PM

All replies

  • Hi,

    How do you set this rule to trigger script?

    Do you check if there any other rules which may be set "stop processing more rules" when new mail arrives?

    I suggest you disable other rules and test if it could be triggered when new mails arrive.

    Friday, October 7, 2016 1:09 AM
  • Hello Anthony,

    What conditions did you choose for triggering the macro? Are macros allowed to run in Outlook?

    Note, as a workaround you may consider handling the NewMailEx event of the Application class in VBA. This event fires once for every received item that is processed by Microsoft Outlook. The item can be one of several different item types, for example, MailItem, MeetingItem, or SharingItem. The EntryIDsCollection string contains the Entry ID that corresponds to that item. 

    The NewMailEx event fires when a new message arrives in the Inbox and before client rule processing occurs. You can use the Entry ID returned in the EntryIDCollection array to call the NameSpace.GetItemFromID method and process the item. Use this method with caution to minimize the impact on Outlook performance. However, depending on the setup on the client computer, after a new message arrives in the Inbox, processes like spam filtering and client rules that move the new message from the Inbox to another folder can occur asynchronously. You should not assume that after these events fire, you will always get a one-item increase in the number of items in the Inbox.


    Friday, October 7, 2016 10:56 AM
  • The rule is trigger by:

    - with 'foo' or 'FOO' in subject

    - on this computer only (I tried toggling this option)

    run Project.ThisOutlookSession.filter

    Wednesday, October 12, 2016 2:47 PM
  • As a test, I have 'enabled all macros'.

    I will take a look at using NewMailEx to see if that works properly.

    Wednesday, October 12, 2016 2:53 PM
  • Hi,

    I test with the same code and rule and It could successfully change the subject.

     Does only this rule not work? How many rules in your account? As far as I know, outlook has limitation of rules if you are using Exchange server. It is 64KB by default. The rule might be disabled when the limit is exceeded.

     I suggest you re-create your PST file or repair Office as a general suggestion.

    Besides, since the issue is more related to the product, I would suggest you post a new thread on the following forum

    Sorry for any inconvenience and have a nice day! 




    Thursday, October 13, 2016 1:56 PM