PDA

View Full Version : Outlook Email Rule execution through shortcut keys (VBA codes)



nbm1515
12-05-2018, 07:30 AM
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

skatonni
12-05-2018, 01:20 PM
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