Rules run on messages as they arrive in the inbox. You don't need a script to move messages to named folders as this is a basic function provided by the rules.
If you want to use a macro to process an existing folder then you need a different approach:
Sub MoveMessages() Dim olFolder As Folder Dim olDestFolder As Folder Dim olItems As Outlook.Items Dim strFind As String Dim i As Long, j As Long: j = 0 strFind = InputBox("Find what text?") If strFind = "" Then GoTo lbl_Exit Set olFolder = Application.Session.PickFolder Set olDestFolder = Application.Session.GetDefaultFolder(olFolderInbox).folders("Test").folders("Test A") Set olItems = olFolder.Items For i = olItems.Count To 1 Step -1 If TypeName(olItems(i)) = "MailItem" Then If InStr(1, olItems(i).Subject, strFind) > 0 Then olItems(i).Move olDestFolder j = j + 1 End If End If Next i MsgBox j & " message items moved" lbl_Exit: Set olItems = Nothing Set olFolder = Nothing Set olDestFolder = Nothing Exit Sub End Sub




Reply With Quote
