Creating Rules in Outlook

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
ShubhamM
Posts: 38
Joined: 08 Nov 2017, 21:38

Creating Rules in Outlook

Post by ShubhamM » 15 Apr 2022, 20:03

Good Day,

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
Thanks so much for any assistance you can provide! Have a great weekend!

BoBo
Posts: 6564
Joined: 13 May 2014, 17:15

Re: Creating Rules in Outlook

Post by BoBo » 16 Apr 2022, 02:38


ShubhamM
Posts: 38
Joined: 08 Nov 2017, 21:38

Re: Creating Rules in Outlook

Post by ShubhamM » 16 Apr 2022, 11:54

Ahh, yes, thank you for sharing that for others as I should have done so myself. I just need to figure out how to have the Rule.Conditions.Subject.Text property to accept strings. I believe the commented out variable Subject_Array creates an object containing an array and is not an array itself so I don't know how to pass the array itself to the property. I'm really crossing my fingers that it can be done/figured out.

Post Reply

Return to “Ask for Help (v1)”