none
E-Mail rules that trigger a VBA script RRS feed

  • Question

  • Hi,

    we want to create an Outlook (2013 currently, but should work in other versions as well if possible) E-Mail rule, which triggers a VBA script, just like this: https://support.microsoft.com/en-us/kb/306108. This is working fine. Now, how do we know in the VBA script, which rule has triggered this script, maybe identified by name or ID? Can it maybe be passed as an argument to the VBA procedure? because in our special case it depends on the "source" rule what to do in VBA

    Thanks in advance



    • Edited by _b_s_ Monday, September 5, 2016 12:43 PM Added version info
    Monday, September 5, 2016 12:35 PM

Answers

  • Hello,

    No, there is no way to get such information. But you can assign a different VBA macro sub for each rule. For example, you can change the business logic and assign a separate VBA sub for each rule in Outlook.

    Also you may consider handling the NewMailEx event of the Application class instead of creating rules in Outlook and assigning a VBA macro to them. The event is fired when a new item is received in the Inbox.

    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.


    [custom.development]

    • Proposed as answer by Chenchen LiModerator Tuesday, September 6, 2016 9:57 AM
    • Marked as answer by _b_s_ Tuesday, September 6, 2016 10:12 AM
    Monday, September 5, 2016 2:31 PM

All replies

  • Hello,

    No, there is no way to get such information. But you can assign a different VBA macro sub for each rule. For example, you can change the business logic and assign a separate VBA sub for each rule in Outlook.

    Also you may consider handling the NewMailEx event of the Application class instead of creating rules in Outlook and assigning a VBA macro to them. The event is fired when a new item is received in the Inbox.

    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.


    [custom.development]

    • Proposed as answer by Chenchen LiModerator Tuesday, September 6, 2016 9:57 AM
    • Marked as answer by _b_s_ Tuesday, September 6, 2016 10:12 AM
    Monday, September 5, 2016 2:31 PM
  • Hi,

    well, I was hoping not to have to reimplement a rule system with VSTO, but it seems to be the only solution that is somewhat acceptable, so I'm going to accept your post above as answer


    • Edited by _b_s_ Tuesday, September 6, 2016 10:12 AM fixed typo
    Tuesday, September 6, 2016 10:11 AM
  • The NewMailEx event can be handled in VBA too. There is no need to develop an add-in for that.

    [custom.development]

    Tuesday, September 6, 2016 10:44 AM
  • Sorry, I didn't explain the background well enough. We are actually building an add-in with VSTO. It is a custom archiving system, and the user should be able to define per e-mail rule, in which "directory" (in a database) e-mails should be archived to automatically. Thus we wanted to use the regular e-mail rule system combined with VBA, and read these setting in the macro. So we needed to identify the rule that activated the VBA script. As you stated, this is not possible, so it is probably the best solution to directly use the NewMailEx event in VSTO
    Tuesday, September 6, 2016 10:59 AM
  • Yeah. You need to implement the business logic in your VSTO plug-in instead.

    [custom.development]

    Tuesday, September 6, 2016 2:10 PM
  • Unfortunately the NewMailEx event does not fire for mails that have arrived while Outlook was not running, so in our case it is quite useless

    Thursday, September 8, 2016 1:56 PM