Consulting

Results 1 to 5 of 5

Thread: Can someone help me with following code to increase/faster outlook VBA Macro Speed ?

  1. #1
    VBAX Newbie
    Joined
    Dec 2018
    Posts
    3
    Location

    Can someone help me with following code to increase/faster outlook VBA Macro Speed ?

    Hi

    Can someone help me with following code to increase/faster outlook VBA Macro Speed ? Currently It taking lot of time run all email rules and getting process slow.



    Sub RunAllInboxRules()
    Dim st As Outlook.Store
    Dim myRules As Outlook.Rules
    Dim rl As Outlook.Rule
    Dim count As Integer
    Dim ruleList As String
    'On Error Resume Next
    
    ' get default store (where rules live)
    Set st = Application.Session.DefaultStore
    ' get rules
    Set myRules = st.GetRules
    
    ' iterate all the rules
    For Each rl In myRules
    ' determine if it's an Inbox rule
    If rl.RuleType = olRuleReceive Then
    ' if so, run it
    rl.Execute ShowProgress:=True
    count = count + 1
    ruleList = ruleList & vbCrLf & rl.Name
    End If
    Next
    
    ' tell the user what you did
    ruleList = "These rules were executed against the Inbox: " & vbCrLf & ruleList
    MsgBox ruleList, vbInformation, "Macro: RunAllInboxRules"
    
    Set rl = Nothing
    Set st = Nothing
    Set myRules = Nothing
    End Sub
    Last edited by Paul_Hossler; 12-14-2018 at 09:56 AM. Reason: Added CODE Tags

  2. #2
    VBAX Expert Logit's Avatar
    Joined
    Sep 2016
    Posts
    606
    Location
    .
    See if this improves things :

    Sub RunAllInboxRules()
    Dim st As Outlook.Store
    Dim myRules As Outlook.Rules
    Dim rl As Outlook.Rule
    Dim count As Integer
    Dim ruleList As String
    'On Error Resume Next
    
    
    With Application
            .ScreenUpdating = False
            .DisplayStatusBar = False
            .Calculation = xlCalculationManual
            .EnableEvents = False
    End With
    
    
    ' get default store (where rules live)
    Set st = Application.Session.DefaultStore
    ' get rules
    Set myRules = st.GetRules
    
    
    ' iterate all the rules
    For Each rl In myRules
    ' determine if it's an Inbox rule
    If rl.RuleType = olRuleReceive Then
    ' if so, run it
    rl.Execute ShowProgress:=True
    count = count + 1
    ruleList = ruleList & vbCrLf & rl.Name
    End If
    Next
    
    
    With Application
           .ScreenUpdating = True
            .DisplayStatusBar = True
            .Calculation = xlCalculationAutomatic
            .EnableEvents = True
    End With
    
    
    ' tell the user what you did
    ruleList = "These rules were executed against the Inbox: " & vbCrLf & ruleList
    MsgBox ruleList, vbInformation, "Macro: RunAllInboxRules"
    
    
    Set rl = Nothing
    Set st = Nothing
    Set myRules = Nothing
    End Sub

  3. #3
    VBAX Newbie
    Joined
    Dec 2018
    Posts
    3
    Location
    Thanks for your reply,

    But I am getting debug/ run error while execution of above code at start of .ScreenUpdating

    I am using this VBA code for outlook rule email or such booster can use with Excel spread sheet VBA macro ?

  4. #4
    VBAX Sage
    Joined
    Apr 2007
    Location
    United States
    Posts
    8,711
    Location
    Quote Originally Posted by Logit View Post
    .
    See if this improves things :
    That looks like Excel. Probably won't work in Outlook
    ---------------------------------------------------------------------------------------------------------------------

    Paul


    Remember: Tell us WHAT you want to do, not HOW you think you want to do it

    1. Use [CODE] ....[/CODE ] Tags for readability
    [CODE]PasteYourCodeHere[/CODE ] -- (or paste your code, select it, click [#] button)
    2. Upload an example
    Go Advanced / Attachments - Manage Attachments / Add Files / Select Files / Select the file(s) / Upload Files / Done
    3. Mark the thread as [Solved] when you have an answer
    Thread Tools (on the top right corner, above the first message)
    4. Read the Forum FAQ, especially the part about cross-posting in other forums
    http://www.vbaexpress.com/forum/faq...._new_faq_item3

  5. #5
    VBAX Sage
    Joined
    Apr 2007
    Location
    United States
    Posts
    8,711
    Location
    If you delete these lines, is it better?

            rl.Execute ShowProgress:=True
            count = count + 1
    Or make ShowProgress := False
    ---------------------------------------------------------------------------------------------------------------------

    Paul


    Remember: Tell us WHAT you want to do, not HOW you think you want to do it

    1. Use [CODE] ....[/CODE ] Tags for readability
    [CODE]PasteYourCodeHere[/CODE ] -- (or paste your code, select it, click [#] button)
    2. Upload an example
    Go Advanced / Attachments - Manage Attachments / Add Files / Select Files / Select the file(s) / Upload Files / Done
    3. Mark the thread as [Solved] when you have an answer
    Thread Tools (on the top right corner, above the first message)
    4. Read the Forum FAQ, especially the part about cross-posting in other forums
    http://www.vbaexpress.com/forum/faq...._new_faq_item3

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •