1. Here's a thread that needs an answer: Better address book
    Dismiss Notice

Outlook 2013 Automation error running VB macro code

Discussion in 'Outlook VBA and Custom Forms' started by Big Red, Dec 22, 2016.

  1. Big Red

    Big Red

    I have several macros that run various rules or groups of rules the move emails between folders in my Outlook 2013 mailbox. This works fine on my current Windows 7 PC. I am in the process of migrating over to Windows 10 also running Outlook 2013. While migrating the rules I ran into a problem where I am unable to run the macros. Each macro I run produces an automation error:

    Run-time error '-2147221233 (8004010f)': Automation error

    Here is the sample code I am trying to run:

    Sub RunForeFrontRule()
    Dim st As Outlook.Store
    Dim myRules As Outlook.Rules
    Dim rl As Outlook.Rule
    Dim runrule As String
    Dim rulename As String
    Dim cf As Folder

    rulename = "Forefront"

    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

    Set rl = Nothing
    Set st = Nothing
    Set myRules = Nothing
    End Sub

    When I try to debug the code it goes straight to the first NEXT and stops. I have been searching high and low trying to find a solution with no luck.

    Please help. I am desperate at this point.

  2. Michael Bauer

    Michael Bauer

    Senior Member
    Click Tools/References. Which entries are checked?
  3. Big Red

    Big Red

    Hi Michael,

    Thank you for your response. Here is the list of entries checked within VB:

    Visual Basic for Applications
    Microsoft Outlook 15.0 Object Library
    OLE Automation
    Microsoft Office 15.0 Object Library
    Microsoft Outlook View Control

    Kind Regards

  4. Michael Bauer

    Michael Bauer

    Senior Member
    Ok, I thought the OLE Automation is missing.

    I'd walk through the code execution step by step by pressing f8, and see where it doesn't behave as expected. For instance, which line is executed before the error comes up, is any rule exucted at all?
  5. Big Red

    Big Red

    I've stepped through all the lines and did not encounter any problems.
  6. Michael Bauer

    Michael Bauer

    Senior Member
    So it´s running through now?
  7. Big Red

    Big Red

    No. If I try to run the code as a whole it still keeps failing with an automation error.
  8. Michael Bauer

    Michael Bauer

    Senior Member
    Maybe a DoEvents before the Next line will be helpful.
  9. Big Red

    Big Red


Share This Page