vbaoutlookrules

Runtime Error - Set olRule = olRules.Item(i) after Microsoft update, where rules setup as 'Through the Specified Account'


ERROR: 2020.05.26 - Since last Microsoft update, code fails on rules setup as 'Through the Specified Account'.

When it hits

Set olRule = olRules.Item(i)

it throws:

Run-time error '-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 does not allow the execution to continue.

Deleting the rule 'Through the Specified Account' allows the code to execute.


Solution

  • SOLVED!

    I found the answer at https://community.spiceworks.com/t/getting-runtime-error-2147467229-80004023-in-excel-vba-macro/743482

    The solution was to delete the registry key: Computer\HKEY_CLASSES_ROOT\WOW6432Node\CLSID{0006F03A-0000-0000-C000-000000000046}