Hello,

Using scripts posted online, I have put together the code below which move a selected email from the inbox to a subfolder.
I have tied this script to a rule
""
Apply this rule after the message arrives
with Subject of Interest in the subject
and on this machine only
run Project1.RuleMoveToFolder
""

How can I edit the code below to run on the emails selected by the rule above instead of the email currently selected in the inbox? I have tried including an if statement to check the subject of the email before moving it to the folder but it didn't work (email with the correct subject is not moved to the folder).

Here is the code:

Sub RuleMoveToFolder(item As MailItem)


 mailboxNameString = "Mailbox - First Name Last Name"


 Dim olApp As New Outlook.Application
 Dim olNameSpace As Outlook.NameSpace
 Dim olCurrExplorer As Outlook.Explorer
 Dim olCurrSelection As Outlook.Selection


 Dim olDestFolder As Outlook.MAPIFolder
 Dim m As Integer


 Set olNameSpace = olApp.GetNamespace("MAPI")
 Set olCurrExplorer = olApp.ActiveExplorer
 Set olCurrSelection = olCurrExplorer.Selection


 Set olDestFolder = olNameSpace.Folders(mailboxNameString).Folders("Inbox").Folders("Folder1").Folders("Subfolder1")


 For m = 1 To olCurrSelection.Count
    Set item = olCurrSelection.item(m)
    
    If InStr(0, item.Subject, "Subject of Interest", vbTextCompare) > 0 Then
     item.Move olDestFolder
    End
 
 Next m


End Sub

Could you please point me in the right direction to apply this code only to emails that get selected by the rule?

Thank you very much.