0
votes

How do I move incoming mail from inbox to specific folder based on the subject name?

  1. If Subject contains Urgent word then move this mail to QuickLook subfolder. Not needed for existing mails in Inbox.
  2. I want to use run as script in my rules wizard for a new rule so it applies to every message that I receive in Inbox.

I know I can achieve it by Outlook rules but need this as macro as per my requirement.

1
Please don't mark it as duplicate, similar questions are not giving me the correct solution.Sai A

1 Answers

0
votes

I got the answer. Save the below script as Module.

Public Sub MoveUrgentMails(myItem As Outlook.MailItem)

 Dim myNameSpace As Outlook.NameSpace
 Dim myInbox As Outlook.Folder
 Dim myDestFolder As Outlook.Folder
 
 Set myNameSpace = Application.GetNamespace("MAPI")
 Set myInbox = myNameSpace.GetDefaultFolder(olFolderInbox)
 Set myDestFolder = myInbox.Folders("QuickLook")
 
 If InStr(myItem.Subject, "Urgent") > 0 Then
    myItem.Move myDestFolder
 End If

End Sub