1. Here's a thread that needs an answer: Modify account template?

Macro to Run Rules

Discussion in 'Outlook VBA and Custom Forms' started by Kash, Jun 28, 2009.

  1. Kash

    Kash

    Guest
    How can I run only specific rules in 2007?
  2. Sue Mosher [MVP]

    Sue Mosher [MVP]

    Guest
    The code sample at http://www.outlookcode.com/codedetail.aspx?id=1266 shows

    how to run all rules against the Inbox. If you want to run only certain

    rules, return each rule using myRules.Item("name of rule") and then call its

    Execute method.

    Sue Mosher,

    "Kash" <Kash@discussions.microsoft.com> wrote in message

    news:E956E6F3-9EC7-4FA4-BE74-FA33EA82134C@microsoft.com...
    > How can I run only specific rules in 2007?
    1 person likes this.
  3. Kash

    Kash

    Guest
    I'm able to run only one macro.. 'Clear categories'
  4. Sue Mosher [MVP]

    Sue Mosher [MVP]

    Guest
    Code?

    Sue Mosher,

    "Kash" <Kash@discussions.microsoft.com> wrote in message

    news:AF6DE91D-F695-44B6-A443-8351FF52C2F4@microsoft.com...
    > I'm able to run only one macro.. 'Clear categories'
  5. Kash

    Kash

    Guest
    Sub RunAllInboxRules()

    Dim st As Outlook.Store

    Dim myRules As Outlook.Rules

    Dim rl As Outlook.Rule

    Dim count As Integer

    Dim ruleList As String

    'On Error Resume Next

    ' get default store (where rules live)

    Set st = Application.Session.DefaultStore

    ' get rules

    Set myRules = st.GetRules

    ' iterate all the rules

    For Each rl In myRules

    ' determine if it's an Inbox rule

    If rl.RuleType = olRuleReceive Then

    ' if so, run it

    rl.Execute ShowProgress:=True

    count = count + 1

    ruleList = ruleList & vbCrLf & rl.Name

    End If

    Next

    ' tell the user what you did

    ruleList = "These rules were executed against the Inbox: " & vbCrLf &

    ruleList

    MsgBox ruleList, vbInformation, "Macro: RunAllInboxRules"

    Set rl = Nothing

    Set st = Nothing

    Set myRules = Nothing

    End Sub
  6. Sue Mosher [MVP]

    Sue Mosher [MVP]

    Guest
    If you step through the code in the debugger, what happens inside the For

    Each loop?

    Sue Mosher,

    "Kash" <Kash@discussions.microsoft.com> wrote in message

    news:0B6F77BD-1685-4FB1-95AC-F506CC69664D@microsoft.com...
    > Sub RunAllInboxRules()
    > Dim st As Outlook.Store
    > Dim myRules As Outlook.Rules
    > Dim rl As Outlook.Rule
    > Dim count As Integer
    > Dim ruleList As String
    > 'On Error Resume Next

    > ' get default store (where rules live)
    > Set st = Application.Session.DefaultStore
    > ' get rules
    > Set myRules = st.GetRules

    > ' iterate all the rules
    > For Each rl In myRules
    > ' determine if it's an Inbox rule
    > If rl.RuleType = olRuleReceive Then
    > ' if so, run it
    > rl.Execute ShowProgress:=True
    > count = count + 1
    > ruleList = ruleList & vbCrLf & rl.Name
    > End If
    > Next

    > ' tell the user what you did
    > ruleList = "These rules were executed against the Inbox: " & vbCrLf &
    > ruleList
    > MsgBox ruleList, vbInformation, "Macro: RunAllInboxRules"

    > Set rl = Nothing
    > Set st = Nothing
    > Set myRules = Nothing
    > End Sub

    > "Kash" <Kash@discussions.microsoft.com> wrote in message
    > news:AF6DE91D-F695-44B6-A443-8351FF52C2F4@microsoft.com...
    > > I'm able to run only one macro.. 'Clear categories'

    >


    "Sue Mosher [MVP]" <suemvp@turtleflock.com> wrote in message

    news:O0jqT$D%23JHA.1488@TK2MSFTNGP03.phx.gbl...
    > The code sample at http://www.outlookcode.com/codedetail.aspx?id=1266
    > shows
    > how to run all rules against the Inbox. If you want to run only certain
    > rules, return each rule using myRules.Item("name of rule") and then call
    > its
    > Execute method.

    > "Kash" <Kash@discussions.microsoft.com> wrote in message
    > news:E956E6F3-9EC7-4FA4-BE74-FA33EA82134C@microsoft.com...
    > > How can I run only specific rules in 2007?


    >
Similar Threads
Forum Title Date
Outlook VBA and Custom Forms Macro to change folder of rules automatically Apr 10, 2014
Outlook VBA and Custom Forms Macro to Write Rules Jun 23, 2009
Outlook VBA and Custom Forms Macro for Reply All in 2013 Outlook Jul 16, 2014
Outlook VBA and Custom Forms Macro/Alert for unreceived email Jul 11, 2014
Using Outlook Auto reply using macro include original email Jul 7, 2014

Share This Page