0
我從網絡的下面的代碼運行Outlook 2010規則。運行規則的宏
我試圖一次只運行一個規則,從組合框中選擇它,但它運行所有規則。
以及我希望它顯示規則的名稱完成後。
Option Explicit
Private st As Outlook.Store
Private myRules As Outlook.Rules
Private rl As Outlook.Rule
Private count As Integer
Private ruleList As String
Private i As Long
Private Sub cmd_close_Click()
Me.cmb_select_rule.Clear
Unload Me
End Sub
Sub RunMyRules()
frmRunRules.Show
End Sub
Private Sub frmRunRules_Initialize()
Set st = Application.Session.DefaultStore
Set myRules = st.GetRules
With Me.cmb_select_rule
.Clear
For Each rl In myRules
.AddItem rl.Name
Next rl
End With
End Sub
Private Sub cmdRun_Click()
Me.Hide
Set st = Application.Session.DefaultStore
Set myRules = st.GetRules
With Me.cmb_select_rule
For i = 0 To .ListCount - 1
If .ListIndex(i) Then
Set rl = myRules.Item(.List(i))
If rl.RuleType = olRuleReceive Then
' if so, run it
rl.Execute ShowProgress:=True
count = count + 1
ruleList = ruleList & vbCrLf & rl.Name
End If
End If
Next i
End With
ruleList = "These rules were executed against the Inbox: " & vbCrLf & ruleList
MsgBox ruleList, vbInformation, "Outlook Rules"
Set rl = Nothing
Set st = Nothing
Set myRules = Nothing
Me.cmb_select_rule.Clear
End Sub