1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61
|
Sub CreateOutlookRule()
Dim OL As Outlook.Application
If UCase(Application) = "OUTLOOK" Then
Set OL = Application
Else
Set OL = CreateObject("outlook.application")
End If
const olFolderInbox= 6
Const olRuleReceive=0
Dim colRules As Object 'Outlook.Rules
Dim oRule As Object 'As Outlook.Rule
Dim colRuleActions As Object 'As Outlook.RuleActions
Dim oMoveRuleAction As Object 'As Outlook.MoveOrCopyRuleAction
Dim oSubjectCondition As Object 'As Outlook.TextRuleCondition
Dim oExceptSubject As Object 'As Outlook.TextRuleCondition
Dim oCategory As Object 'As Outlook.AssignToCategoryRuleAction
Dim oInbox As Object 'As Outlook.folder
Dim oMoveTarget As Object 'As Outlook.folder
Set oInbox = OL.Session.GetDefaultFolder(olFolderInbox)
Set oMoveTarget = oInbox.Folders("test")
Set colRules = OL.Session.DefaultStore.GetRules()
Set oRule = colRules.Create("TEST", olRuleReceive)
'Deplacer le message vers un dossier
Set oMoveRuleAction = oRule.Actions.MoveToFolder
With oMoveRuleAction
.Enabled = True
.folder = oMoveTarget
End With
'Ajouter le message à une catégorie
Set oCategory = oRule.Actions.AssignToCategory
With oCategory
.Enabled = True
.Categories = Array("test")
End With
'Mots que le sujet doit contenir
Set oSubjectCondition = oRule.Conditions.Subject
With oSubjectCondition
.Enabled = True
.Text = Array("test")
End With
'Mots que le sujet ne doit pas contenir
Set oExceptSubject = oRule.Exceptions.Subject
With oExceptSubject
.Enabled = True
.Text = Array("RE:", "FW:")
End With
colRules.Save
End Sub |