jfslicer
05-17-2017, 04:51 PM
Hi! I'm trying to build a Macro to quickly go through a bunch of disabled rules to clean out a folder in outlook. I am starting with the following code, but there are three issues with it currently.
1) I want it to only run in a specific folder. I know this is a sub feature of execute rule, but every time I add it in the line turns read and yells "You're a bad coder" at me.
2) I would like the loop command to only apply to disabled rules
3) I would like the loop command to ignore one specific rule labelled ruleName. This is coded in there already, but it doesn't appear to work. Several test have verified failure.
Also, this code is mostly borrowed form another site and this is my first time coding in Outlook, why does the code have Set all the abbreviations to nothing at the end of the code? I haven't seen that in all my code building for Excel.
Sub RunRules()
Dim st As Outlook.Store
Dim myRules As Outlook.Rules
Dim rl As Outlook.Rule
Dim count As Integer
Dim ruleList As String
Dim ruleName As String
ruleName = "Rule"
On Error Resume Next
Set st = Application.Session.DefaultStore
Set myRules = st.GetRules
For Each rl In myRules
If rl.RuleType = olRuleReceive And rl.Name <> ruleName Then
rl.Execute ShowProgress:=True, RuleExecuteOption:=1
count = count + 1
ruleList = ruleList & vbCrLf & rl.Name
End If
Next
Set rl = Nothing
Set st = Nothing
Set myRules = Nothing
End Sub
Thanks!
1) I want it to only run in a specific folder. I know this is a sub feature of execute rule, but every time I add it in the line turns read and yells "You're a bad coder" at me.
2) I would like the loop command to only apply to disabled rules
3) I would like the loop command to ignore one specific rule labelled ruleName. This is coded in there already, but it doesn't appear to work. Several test have verified failure.
Also, this code is mostly borrowed form another site and this is my first time coding in Outlook, why does the code have Set all the abbreviations to nothing at the end of the code? I haven't seen that in all my code building for Excel.
Sub RunRules()
Dim st As Outlook.Store
Dim myRules As Outlook.Rules
Dim rl As Outlook.Rule
Dim count As Integer
Dim ruleList As String
Dim ruleName As String
ruleName = "Rule"
On Error Resume Next
Set st = Application.Session.DefaultStore
Set myRules = st.GetRules
For Each rl In myRules
If rl.RuleType = olRuleReceive And rl.Name <> ruleName Then
rl.Execute ShowProgress:=True, RuleExecuteOption:=1
count = count + 1
ruleList = ruleList & vbCrLf & rl.Name
End If
Next
Set rl = Nothing
Set st = Nothing
Set myRules = Nothing
End Sub
Thanks!