0

Outlook 2010 ルールを実行するために、Web から以下のコードを取得しました。

コンボボックスから選択して一度に 1 つのルールのみを実行しようとしていますが、すべてのルールが実行されます。

同様に、終了したらルールの名前を表示したいと思います。

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
4

1 に答える 1

0
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
rulename = "Your Rule Name"
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

単一のルールを実行する上記を試してください。ルール名を既存のルールの 1 つに編集し、Whater_Finished を任意のものに編集するだけです...コンボ ボックスはありませんが、開始するのに適した場所です。

于 2014-07-31T13:51:20.047 に答える