Outlook VBA - 运行时错误 - 设置 olRule = olRules.Item(i)

问题描述 投票:0回答:1

错误:2020.05.26 - 自上次 Microsoft 更新以来,当它遇到 Set olRule = olRules.Item(i) 行时,它无法将规则设置为“通过指定帐户”,并抛出:运行时错误“-2146664191 [800c8101]

Private Function FindRule(strRuleName As String) As Boolean
     'error handler
    On Error GoTo ErrorHandler
    
    'default process boolean to failed
    FindRule = False
         
    'open rules object
    Set olRules = Outlook.Application.Session.DefaultStore.GetRules

    'loop through rules to see if the rule is in the rules list    
    If olRules.Count = 0 Then
    'no rules, so it can't exist
        FindRule = False
    Else
    'check the list of rules
        'For i = olRules.Count To 1 Step -1
        For i = 1 To olRules.Count
            Set olRule = olRules.Item(i)
            If olRule.Name = strRuleName Then
                FindRule = True
                Exit For
            End If
        Next i
    End If
    
    'rule not found. let folks know
    If FindRule = False Then
        Err.Raise 60001, "Rule Error", "Rule not found!"
    End If
    
ExitFunction:
    'skip error handler
    Exit Function
    
ErrorHandler:
    'display error
    MsgBox Err.Description, vbExclamation + vbOKCancel, "FindRule - Error: " & CStr(Err.Source)
    'clear error
    Err.Clear
    'return failed boolean
    FindRule = False

End Function

'OnError Resume Next'不允许继续执行。删除“通过指定帐户”规则允许代码执行。

vba outlook rules
1个回答
0
投票

错误为

E_ACCT_NOT_FOUND
,表示规则引用的账户不再存在。编辑规则并将其指向右侧 帐户。

© www.soinside.com 2019 - 2024. All rights reserved.