I previously asked about getting rules to work on multiple accounts. It was partially answered, however rules do not work on the second account.
When running the script the progress window pops up, but no rules run.
Debug output of the rules lists all the rules for the account. If I manually run the rules, it does work.
Decided to split the macro into two. Running the first macro works for the first account. But the second macro for the second account doesn't work.
My assumption is it is trying to run those rules on the first account, but not succeeding because those rules do not exist.
Sub RunTest_AccountOne()
Dim storeRules As Rules
Dim storeRule As Rule
Dim allStores As Stores
Dim myStore As Store
Dim emailaccount As String
Set allStores = Session.Stores
emailaccount = "example@example.com.au"
For Each myStore In allStores
'On Error Resume Next
'If needed, place just before the expected error.
'Follow closely with On Error GoTo 0 to return to normal error handling.
'Debug.Print myStore.DisplayName & " " & myStore.ExchangeStoreType
Select Case myStore.DisplayName
Case emailaccount
'Debug.Print " ExchangeStoreType matched: " _
& myStore.DisplayName & " " & myStore.ExchangeStoreType
Set storeRules = myStore.GetRules()
For Each storeRule In storeRules
'Below only works if it is the first account added to Outlook.
'storeRule.Execute 'ShowProgress:=False
'Below shows the progress window for rules running, but doesn't apply anything.
storeRule.Execute ShowProgress:=True, Folder:=myStore.GetDefaultFolder(olFolderInbox), RuleExecuteOption:=olRuleExecuteAllMessages
'Below outputs a bunch of "Inbox" messages in the console, which coincides with the amount of rules, as expected.
'Debug.Print myStore.GetDefaultFolder(olFolderInbox)
Next
End Select
Next
End Sub
I have tried with RuleExecuteOption:=olRuleExecuteAllMessages
and without.