0
votes

Why is this code to run all enabled rules does not run in outlook-2016? I used it without any problem on outlook 2007, 2010 and 2013, but it is not working in outlook 2016.

Sub OrginalRunActiveCatInboxRules()

Dim Session As Outlook.NameSpace
Dim Report As String
Dim currentItem As Object
Dim currentRule As Outlook.Rule
Dim rules As Outlook.rules
Dim ruleList As String
Set Session = Application.Session

Set rules = Session.DefaultStore.GetRules()

For Each currentRule In rules

   If currentRule.RuleType = olRuleReceive Then         
'determine if it’s an Inbox rule, if so, run it
       If currentRule.Enabled Then
           If Left(currentRule.name, 4) = "Cat." Then
               MsgBox currentRule.name
               currentRule.Execute ShowProgress:=True   
' Sortering niet laten zien
'               ruleList = ruleList & vbCrLf & currentRule.Name
           End If
       End If
   End If
 Next


' tell the user what you did
' ruleList = "These rules were executed against the Inbox: " & vbCrLf & ruleList
' MsgBox ruleList, vbInformation, "Macro: RunAllActiveInboxRules"
Set rules = Nothing
Set currentRule = Nothing
End Sub

The codes runs until next, but gives a error there. It does not matter if the first rule is enabled or not, starts with Cat. or not. It just won't go to the next item in the loop, but generates a error.

What can I do to make the code working again?

2
What is the error? – Alex K.
Error: -2146664191 (800c8101) According to the help this error has something to to wit the OlkCategory.BackColor Property, Which seems nonsense to me. – user1886216
The rule itself doesn't seem to be relevant. If I leave out the execution the error pops up. I set Outlook to perform macro's without any restrictions. – user1886216

2 Answers

1
votes

Check in the rules wizard if some of the rules are marked 'From other computer'. If you have any like this, then the code will break at the line:

For Each currentRule In rules

I have the same issue now - took me a lot of troubleshooting to figure this out. One more thing that could be an issue: if any of the rules are broken, for example refer to a directory that does not exist, the rules object will not contain any rules.

If troubleshooting the above, remove all the suspicious rules and start adding them one by one back.

-1
votes

One of mine was marked "on this computer" when I unselected this option, the script worked again.