The following code works to move emails to the "FolderName" but is I get a response from Microsoft that an email was not received or did come thru etc., when I try to move the email coming back from Microsoft as an automatic reply, I can't move it to a folder. So what do I change for that type of response please:
Sub MoveSelectedMessagesToFolder()
Dim objFolder As outlook.MAPIFolder, objInbox As outlook.MAPIFolder
Dim objNS As outlook.NameSpace, ObjItem As outlook.mailItem
Set objNS = Application.GetNamespace("MAPI")
Set objInbox = objNS.GetDefaultFolder(olFolderInbox)
On Error Resume Next
Set objFolder = objInbox.Folders("FolderName")
'Assume this is a mail folder
If objFolder Is Nothing Then
MsgBox "This folder doesn’t exist!", vbOKOnly + vbExclamation, "INVALID FOLDER"
End If
If Application.ActiveExplorer.Selection.Count = 0 Then
'Require that this procedure be called only when a message is selected
Exit Sub
End If
For Each ObjItem In Application.ActiveExplorer.Selection
If objFolder.DefaultItemType = olMailItem Then
If ObjItem.Class = olMail Then
ObjItem.Move objFolder
End If
End If
Next
Set ObjItem = Nothing
Set objFolder = Nothing
Set objInbox = Nothing
Set objNS = Nothing
End Sub