I'm trying to create rules on Outlook based on text in the subject line of a received email, moving the email to a newly created folder. The rule is created and all aspects of the code below work with the exception of the Subject Condition, where I believe SubjectCondition.Text := "test" is not accepting "test" as the string to capture. Based on the information in the following Microsoft Docs, the text property requires being fed an Array but I'm not sure how to do this either:
https://docs.microsoft.com/en-us/office/vba/api/outlook.textrulecondition.text
Code: Select all
Project_Number := 12345, Project_Name := "Some Company Name"
Folder_Name := Project_Number " - " Project_Name
Outlook_App := ComObjActive("Outlook.Application")
NameSpace := Outlook_App.GetNamespace("MAPI")
New_Folder := NameSpace.GetDefaultFolder(6).Folders.Add(Folder_Name)
Rules := Outlook_App.Session.DefaultStore.GetRules()
New_Rule := Rules.Create(Folder_Name, 0) ;0 = received emails
;Subject_Array := Array("test1", "test2")
SubjectCondition = New_Rule.Conditions.Subject
SubjectCondition.Enabled := 1
SubjectCondition.Text := "test" ;THIS HERE DOES NOT WORK - Also tried Array("test1", "test2") here to no avail
Action_MoveToFolder := New_Rule.Actions.MoveToFolder
Action_MoveToFolder.Enabled := 1
Action_MoveToFolder.Folder := New_Folder
Action_NewItemAlert := New_Rule.Actions.NewItemAlert
Action_NewItemAlert.Enabled := 1
Action_NewItemAlert.Text := New_Folder
Rules.Save
;ListVars
Return