I have created a folder on root, not under Inbox. What is the syntax to move to root folder?
I'm getting error:
The attempted operation failed
An Object Could not be found
Debug points to the below line myRestrictItems(i).Move myFolder.folders("Business")
Option Explicit
Public Sub Example()
Dim myNamespace As Outlook.NameSpace
Dim myFolder As Outlook.MAPIFolder
Dim myRestrictItems As Outlook.Items
Dim myItems As Outlook.Items
Dim myItem As Object
Dim i As Long
Dim Filter As String
Dim Msg As String
Set myNamespace = Application.GetNamespace("MAPI")
Set myFolder = myNamespace.GetDefaultFolder(olFolderInbox)
Set myItems = myFolder.Items
Filter = "@SQL=" & Chr(34) & "urn:schemas:httpmail:datereceived" & _
Chr(34) & " >= '01/01/2018' And " & _
Chr(34) & "urn:schemas:httpmail:datereceived" & _
Chr(34) & " < '23/03/2018' And " & _
Chr(34) & "urn:schemas:httpmail:fromname" & _
Chr(34) & "Like '%Jayakumar Krishnamoorthy%'"
Set myRestrictItems = myItems.Restrict(Filter)
For i = myRestrictItems.Count To 1 Step -1
myRestrictItems(i).Move myFolder.folders("Business")
'Msg = myRestrictItems.Count & " Items in " & myFolder.Name & " Folder"
'MsgBox (Msg)
Next
End Sub