none
Automation error running VB macro code RRS feed

  • Question

  • I have several macros that run various rules or groups of rules that 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
    Next
    
    Set rl = Nothing
    Set st = Nothing
    Set myRules = Nothing
    End Sub

    When I try to debug the code it goes straight to the NEXT line 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.

    Thanks

    Wednesday, January 4, 2017 1:57 PM

All replies

  • Hello Caffeine,

    The Store.GetRules method returns a Rules collection. I'd suggest checking the number of rules there. The Count property returns an integer indicating the count of objects in the specified collection. 


    profile for Eugene Astafiev at Stack Overflow, Q&A for professional and enthusiast programmers

    Wednesday, January 4, 2017 3:38 PM
  • Hi Caffeine Withdrawal,

    I try to debug the code on my side and find that there is no error in the code.

    as you already mentioned that you are running the same code successfully in windows 7.

    so I focus on the error.

    I find that "Run-time error '-2147221233 (8004010f)': Automation error" occurs when it not found the folder.

    so please try to check that all the folders are available at correct location and also check that all the rules are proper.

    so when loop runs it can find the rule and folder.

    Regards

    Deepak


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Thursday, January 5, 2017 1:53 AM
    Moderator
  • Thank you for your response. What do you mean by "checking the number of rules"? All the rules are server-based so they are all located on the Exchange server. There shouldn't be any difference in the number of rules that both PCs see.

    Thanks

    Friday, January 6, 2017 10:58 AM
  • Thank you for your response. All the folders and all the rules are server-based so nothing is missing as far as that's concerned. 

    To further test this, I decided to run this rule on another Windows 7 PC (brand new build) and surprisingly it is doing the same thing as the Windows 10 PC. I am completely baffled right now.

    Thanks

    Friday, January 6, 2017 11:00 AM
  • You need to set up rules in Outlook. 

    profile for Eugene Astafiev at Stack Overflow, Q&A for professional and enthusiast programmers

    Friday, January 6, 2017 2:17 PM
  • I have rules in Outlook. ??
    Friday, January 6, 2017 6:36 PM
  • Hello Caffeine,

    I have notice the following statement:

    All the rules are server-based so they are all located on the Exchange server.

    So, did you try to set up rules in Outlook, not Exchange?


    profile for Eugene Astafiev at Stack Overflow, Q&A for professional and enthusiast programmers

    Saturday, January 7, 2017 9:28 PM