If you have a rule whose condition is “with specific words in the subject” and often want to add an email’ subject to this condition, you can use the method in this post. It can let you quickly get it without needs to find and change this rule manually.
Perhaps you’ve created an Outlook rule which will automatically do something with the emails whose subjects contain specific words. Now, you want to add the subjects of some emails to this rule condition. In general, you have to first write down the subjects and then open “Rules and Alerts” dialog box to change the rule condition manually. Apparently, it is quite troublesome. If you frequently add the new subjects to this rule’s condition, you can use the following way, which is very efficient.
Add the Subjects of Multiple Emails to the Condition of a Specific Rule
- To begin with, start Outlook program.
- Then, get access to Outlook VBA editor via tapping “Alt + F11”.
- Next, in the new window, put the code below into a module.
Sub AddSubjectsOfMultipleEmailsToConditionSpecificRule() Dim objSelection As Outlook.Selection Dim objMail As Outlook.MailItem Dim objDictionary As Object Dim objRules As Outlook.Rules Dim objSpecificRule As Outlook.Rule Dim objRuleCondition As Outlook.RuleCondition Dim objTextRuleCondition As Outlook.TextRuleCondition Dim strTextArray As Variant Dim varSubjects As Variant Dim varNewTextArray As Variant 'Get the selected emails Set objSelection = Outlook.Application.ActiveExplorer.Selection Set objDictionary = CreateObject("Scripting.Dictionary") For Each objItem In objSelection If TypeOf objItem Is MailItem Then Set objMail = objItem If objDictionary.Exists(LCase(objMail.Subject)) = False Then objDictionary.Add LCase(objMail.Subject), 1 End If End If Next 'Get the specific rule, change the rule name as per your own case Set objRules = Outlook.Application.Session.DefaultStore.GetRules Set objSpecificRule = objRules.Item("Auto Flag Mails with Specific Texts in Subjects") 'Add the subjects to the rule condition For Each objRuleCondition In objSpecificRule.Conditions If objRuleCondition.ConditionType = olConditionSubject Then If objRuleCondition.Enabled = True Then Set objTextRuleCondition = objRuleCondition strTextArray = objTextRuleCondition.Text varSubjects = objDictionary.Keys varNewTextArray = Split(Join(strTextArray, ",") & "," & Join(varSubjects, ","), ",") objTextRuleCondition.Text = varNewTextArray End If End If Next objRules.Save MsgBox "Complete!", vbInformation + vbOKOnly End Sub
- After that, for future convenience, add this macro to Quick Access Toolbar or ribbon by referring to “Optional Step” in “How to Run VBA Code in Your Outlook“.
- Finally, exit VBA editor and have a try.
- First off, select the emails whose subjects you want to add to the rule.
- Then, click the newly added macro button.
- After macro finishes, go to “File” menu and click “Manage Rules & Alerts” button.
- In the “Rules and Alerts” dialog, pitch on the specific rule to check its condition. You can see that the email subjects have been in the condition.
Protect Your Outlook Data
Though Outlook is admittedly vulnerable, you still can make enough precautions to safeguard your Outlook data from loss. Above all, you ought to regularly back up your PST files. In this way, even if Outlook is corrupted, you can easily recover PST data from backups. Yet, if you have no backup, you still have a choice. That is to take recourse to a robust PST fix utility, such as DataNumen Outlook Repair.
Shirley Zhang is a data recovery expert in DataNumen, Inc., which is the world leader in data recovery technologies, including corrupted mdf and outlook repair software products. For more information visit www.datanumen.com