Move E-Mails to Another Folder

Status
Not open for further replies.
Re: Need help with saving "sent items" email automatically to desktop folder

Any update soon?

- - - Updated - - -

Any update soon?
 
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
 
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
 
This line: If ObjItem.Class = olMail Then tell it to work for mail. I think the autoreplies are reports, so you could try using olreportitem:
If ObjItem.Class = olMail or If ObjItem.Class = olreportitem then
 
I added that exact line you posted but there is the error re the word "If" in the middle
 
I also tried the following and it did not do it:

If ObjItem.Class = olMail Or olreportitem Then
ObjItem.Move objFolder
 
You need ObjItem.Class = but not the If. (Sorry about that).
 
So is this the line?

ObjItem.Class = olMail or If ObjItem.Class = olreportitem then
 
No.
If ObjItem.Class = olMail or ObjItem.Class = olreportitem then
 
I did it and no error but did not move the email......anything else to try please?
 
No, I have no idea why it's not working. Add the Message Class field to the view and see what message class it is - maybe it's not a report.
 
Don't understand what to add and where? Details please?
 
You could always remove this - If ObjItem.Class = olMail Then - and the matching end if.
 
Please explain what to do as I simply set it up as If ObjItem.Class = olreportitem then but it did not work
 
Sheesh... all this time wasted on a typo. I went from memory and it's not olreportitem, it's olreport. I should have picked up my error when you didn't correct the case when you said it didn't work. :( Always remember that the VB Editor will fix the case and if something like olMail is upper/lower, olwhatever will convert to upper/lower, if it's correct. If it doesn't convert, its not correct. :( :( :(
 
BTW, if you wanted to move everything in the folder, change
If ObjItem.Class = olMail Or ObjItem = olReport Then
ObjItem.Move objFolder
End If

to just

ObjItem.Move objFolder
 
Status
Not open for further replies.
Similar threads
Thread starter Title Forum Replies Date
P when i move inbox mails to another folder in outlook the mail disappears Using Outlook 1
F Excel VBA to move mails for outlook 365 on secondary mail account Outlook VBA and Custom Forms 1
Eike Move mails via macro triggered by the click of a button? Outlook VBA and Custom Forms 0
F Move mails from Deleted Items folder back to its original folder where the mails got deleted Using Outlook 0
P move mails after send to central mailbox-sent items folder Using Outlook 4
H Move Selected emails to Local Drive Outlook VBA and Custom Forms 0
A Search folder and move the email Outlook VBA and Custom Forms 0
A Outlook 365 (OutLook For Mac)Move "On My Computer" Folder Items From Old To New Mac Computer Using Outlook 3
HarvMan Outlook 365 - Rule to Move an Incoming Message to Another Folder Using Outlook 4
humility36 Cannot move emails to archive - 440 error Outlook VBA and Custom Forms 1
B Outlook 2019 Automatically move email after assigning category Using Outlook 4
C Trying to move messages between imap accounts/folders Using Outlook 5
M Move command Outlook VBA and Custom Forms 11
C Code to move mail with certain attachment name? Does Not work Outlook VBA and Custom Forms 3
B Move emails from one account to another Outlook VBA and Custom Forms 2
J Quick steps delete original email and move reply/sent email to folder Using Outlook 2
N How to add or delete items to Move dropdown Menu Using Outlook 0
Commodore Unable to move message Using Outlook 3
N Line to move origEmail to subfolder within a reply macro Outlook VBA and Custom Forms 0
C Move or copy from field to field Outlook VBA and Custom Forms 0
T Outlook 365 Move newly created tasks automatically on save. Outlook VBA and Custom Forms 1
NVDon Create new Move To Folder list Outlook VBA and Custom Forms 0
P Print attachments automatically and move the mail to an existing folder called "Ted" Outlook VBA and Custom Forms 4
T Macro to move reply and original message to folder Outlook VBA and Custom Forms 6
F VBA to move email from Non Default folder to Sub folders as per details given in excel file Outlook VBA and Custom Forms 11
J Dopey move - deleted profile Using Outlook 1
GregS Outlook 2016 Move Outlook to new computer? Using Outlook 4
Witzker Macro to move @domain.xx of a Spammail to Blacklist in Outlook 2019 Outlook VBA and Custom Forms 7
G Move tasks up/down todo list by VBA Outlook VBA and Custom Forms 1
S Macro to move “Re:” & “FWD:” email recieved the shared inbox to a subfolder in outlook Outlook VBA and Custom Forms 0
S Outlook Macro to move reply mail based on the key word in the subjectline Outlook VBA and Custom Forms 0
D Move Email with Attachment to Folder Outlook VBA and Custom Forms 3
G Cannot Move Autocomplete File to New Computer Using Outlook 15
M Move to Folder Using Outlook 1
P Move emails between 2 mailboxes. Using Outlook 0
C Copy Move item won't work Outlook VBA and Custom Forms 2
N Macro to move all recipients to CC while replying Outlook VBA and Custom Forms 0
Commodore Move turns into "copy" Using Outlook 3
R List folders in a combo box + select folder + move emails from inbox to that folder + reply to that email Outlook VBA and Custom Forms 1
Jennifer Murphy Ctrl+Tab sometimes will not move through text a word at a time Using Outlook 1
V Outlook 2016 will not move emails in search results Using Outlook 4
M move to iCloud not working in outlook calendar Using Outlook 12
A Create date folder and move messages daily Outlook VBA and Custom Forms 1
Commodore Folders always closed in move/copy items dialog box Using Outlook 3
C Move Outlook 2007 to new PC with Outlook 365 Using Outlook 3
C Can't move folder, the folder is full Using Outlook 0
Nadine Rule to move attachments with specific name Outlook VBA and Custom Forms 1
A Move email items based on a list of email addresses Outlook VBA and Custom Forms 40
T Move calendar invites to new calendar Using Outlook 5
O Rule to move (specific) messages from Sent folder to Specific folder Using Outlook 1

Similar threads

Back
Top