Consulting

Results 1 to 2 of 2

Thread: Outlook Email Rule execution through shortcut keys (VBA codes)

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

    Outlook Email Rule execution through shortcut keys (VBA codes)

    Hi All,


    I looking for suggestion for my following VBA code to execute all predefine MS outlook email rules. I have observed email rules can be executed by pressing shortcut keys (Alt+ h + rr + l + r + e + o + c ). However, my following VBA programme does not work well and it leave rule list window open at last. So not sure its works or not.

    It would be great help if someone can look into code and help me to execute all email rules through short cut keys

    Following VBA macro code open outlook email rule window > select all rules > press run now button > then close rule window > give notification message alert at last


    Outlook VBA Code:



    Sub SpecialCharExample()
    SendKeys "%(h)", True
    SendKeys "%(rr)", True
    SendKeys "%(l)", True
    SendKeys "%(r)", True
    SendKeys "%(e)", True
    SendKeys "%(o)", True
    SendKeys "%(c)", True
    SendKeys ("%{TAB}")
    SendKeys "%{F4}", True
    SendKeys ("{ENTER}")


    ' tell the user what you did
    ruleList = "All rules were executed against the Inbox " & vbCrLf & ruleList
    MsgBox ruleList,

    End Sub

  2. #2
    VBAX Mentor skatonni's Avatar
    Joined
    Jun 2006
    Posts
    347
    Location
    Looks like this is what you want to do.

    Option Explicit
    
    Sub RunAllInboxRules()
    
        ' http://www.outlookcode.com/codedetail.aspx?id=1266
        
        Dim st As Store
        Dim myRules As rules
        Dim rl As Rule
        Dim ruleList As String
         
        ' get default store (where rules live)
        Set st = 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
                
                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"
        
    End Sub
    To debug, mouse-click anywhere in the code. Press F8 repeatedly to step through the code. http://www.cpearson.com/excel/DebuggingVBA.aspx

    If your problem has been solved in your thread, mark the thread "Solved" by going to the "Thread Tools" dropdown at the top of the thread. You might also consider rating the thread by going to the "Rate Thread" dropdown.

Tags for this Thread

Posting Permissions

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