目标:运行我的所有客户端规则。总计269。
问题:代码一次只运行一条规则。
尝试的解决方法尝试/想法:我的规则在列表中运行的数组。由于我在编译数组方面没有太多经验,因此遇到了一些问题。
Sub RunAllInboxRules()
Dim st As Outlook.Store
Dim myRules As Outlook.rules
Dim rl As Outlook.Rule
Dim runrule As String
Dim rulename As String
'Rule name intended to run
rulename = "ABC 123"
Set st = Application.Session.DefaultStore
Set myRules = st.GetRules
Set cf = Application.ActiveExplorer.CurrentFolder
For Each rl In myRules
If rl.RuleType = olRuleReceive Then
If rl.name = rulename Then
rl.Execute ShowProgress:=True, Folder:=cf
runrule = rl.name
End If
End If
Next
ruleList = "Rule was executed correctly:" & vbCrLf & runrule
MsgBox ruleList, vbInformation, "Macro: Whatever_Finished"
Set rl = Nothing
Set st = Nothing
Set myRules = Nothing
End Sub
答案 0 :(得分:0)
每次迭代集合中的所有规则时,都不应该检查规则名称:
Sub RunAllInboxRules()
Dim st As Outlook.Store
Dim myRules As Outlook.rules
Dim rl As Outlook.Rule
Dim rulelist As String
Set st = Application.Session.DefaultStore
Set myRules = st.GetRules
Set cf = Application.ActiveExplorer.CurrentFolder
For Each rl In myRules
rl.Execute ShowProgress:=True, Folder:=cf
ruleList = "Rule was executed correctly:" & vbCrLf & rl.Name
MsgBox ruleList, vbInformation, "Macro: Whatever_Finished"
Next
Set rl = Nothing
Set st = Nothing
Set myRules = Nothing
End Sub
您可能会发现Getting Started with VBA in Outlook 2010文章很有帮助。
答案 1 :(得分:0)
您可以使用.IsLocalRule
来应用仅限客户的规则。
Private Sub RunClientOnlyRules()
Dim st As store
Dim myRules As rules
Dim myFolder As Folder
Dim rl As Rule
Set st = Session.DefaultStore
Set myRules = st.GetRules
Set myFolder = ActiveExplorer.CurrentFolder
For Each rl In myRules
If rl.RuleType = olRuleReceive Then
If rl.IsLocalRule Then
rl.Execute ShowProgress:=True, Folder:=myFolder
End If
End If
Next
ExitRoutine:
Set st = Nothing
Set myRules = Nothing
Set myFolder = Nothing
Set rl = Nothing
MsgBox "Done."
End Sub