Learn how to provision tenants, synchronize on-premise Active Directory, implement Single Sign-On, customize Office deployment, and protect your organization with eDiscovery and DLP policies. Only from Platform Scholar.
Sub AddToRule_RETAIL() Dim bFound As Boolean bFound = False Dim colRules As Outlook.Rules Dim oRule As Outlook.Rule Set colRules = Application.Session.DefaultStore.GetRules() '--- find the rule object ... For Each ruleItem In colRules Debug.Print ruleItem.Name If ruleItem.Name = "Photography" Then Set oRule = ruleItem bFound = True Exit For End If Next If bFound = False Then MsgBox "Rule 'Photography' not found!" Exit Sub End If '--- get selected item email address ' Dim Session As Outlook.NameSpace Dim currentExplorer As Explorer Dim Selection As Selection Dim currentItem As Object Dim currentMail As MailItem Dim currentSenderAddress As String Set currentExplorer = Application.ActiveExplorer Set Selection = currentExplorer.Selection '--- for all items do... For Each currentItem In Selection If currentItem.Class = olMail Then Set currentMail = currentItem currentSenderAddress = currentMail.SenderEmailAddress '-- add it ... Set oFromCondition = oRule.Conditions.From With oFromCondition .Recipients.Add (currentSenderAddress) End With '-- Update the server and display progress dialog colRules.Save End If Next End Sub
Add your voice to the tech community where 5M+ people just like you are talking about what matters.
Join the community of 500,000 technology professionals and ask your questions.