Move E-Mails to Another Folder

Status
Not open for further replies.

LMS

Senior Member
Outlook version
Email Account
Exchange Server
Please explain what to do as I simply set it up as If ObjItem.Class = olreportitem then but it did not work
 

LMS

Senior Member
Outlook version
Email Account
Exchange Server
So just use the line:

If ObjItem.Class = olMail Or ObjItem = olReport Then
ObjItem.Move objFolder
 

LMS

Senior Member
Outlook version
Email Account
Exchange Server
Can you please write in exactly what I am supposed to change re the following:

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
 

LMS

Senior Member
Outlook version
Email Account
Exchange Server
I did the Message Class and it shows up as REPORT.IPM.NOTE.NDR So is there something to change to make it work
 

LMS

Senior Member
Outlook version
Email Account
Exchange Server
I did the Message Class and it shows up as REPORT.IPM.NOTE.NDR So is there something to change to make it work
 

Diane Poremsky

Senior Member
Outlook version
Outlook 2016 32 bit
Email Account
Office 365 Exchange
So just use the line:
If ObjItem.Class = olMail Or ObjItem = olReport Then
ObjItem.Move objFolder
This should work. Oh wait, another typo... you need objitem.class:

If ObjItem.Class = olMail Or ObjItem.class = olReport Then
 

LMS

Senior Member
Outlook version
Email Account
Exchange Server
I tried what you wrote and it does not move the email.
 

LMS

Senior Member
Outlook version
Email Account
Exchange Server
I appreciate it....so here is the full code with what you said....so please take one more look at it and see if there is anything ot change or add please:

Sub MoveSelectedMessagesToFolderUndeliveredEmails()
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("Undelivered E-Mails")
'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 Or ObjItem.Class = olReport Then
ObjItem.Move objFolder
End If
End If
Next
Set ObjItem = Nothing
Set objFolder = Nothing
Set objInbox = Nothing
Set objNS = Nothing
End Sub
 

larry

Senior Member
Outlook version
Outlook 2010 64 bit
Email Account
Exchange Server
I'm no programmer and I don't play one on TV, but do you need to identify if it's a message? Your code sample runs on selected messages, so you only select the ones that you want moved. Then you could remove the If objFolder.DefaultItemType = olMailItem Then line and the end if after ObjItem.Move objFolder.

It seems like you are putting a lot of effort into a technological solution for a simple issue. The ROI can't be that great? I'd add the Undelivered E-Mails folder to the Favorite folder list so it's easy to find and drag the bounced mail to it.
 

LMS

Senior Member
Outlook version
Email Account
Exchange Server
I appreciate it....so here is the full code with what you said....so please take one more look at it and see if there is anything ot change or add please:

Sub MoveSelectedMessagesToFolderUndeliveredEmails()
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("Undelivered E-Mails")
'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 Or ObjItem.Class = olReport Then
ObjItem.Move objFolder
End If
End If
Next
Set ObjItem = Nothing
Set objFolder = Nothing
Set objInbox = Nothing
Set objNS = Nothing
End Sub
 

Forum Admin

Senior Member
Try dimming objitem as variant or object instead of mailitem. or just dim it:

dim objItem

@mrsadmin used olreports but in the code she used, it was dimmed as a variant.
 

LMS

Senior Member
Outlook version
Email Account
Exchange Server
I tried the different ways re Dim and nothing worked. Any other ideas?
 

LMS

Senior Member
Outlook version
Email Account
Exchange Server
Thru a Microsoft Forum, I found the following which moves the report, but not all selected, just one report each time...so what can we change to this so when I select more than one report email, it moves all of them

Sub MoveSelectedMessagesToFolderUndeliveredEmails4()
Dim objFolder As outlook.MAPIFolder, objInbox As outlook.MAPIFolder
Dim objNS As outlook.NameSpace, objItem As outlook.mailItem
Dim olReport
Dim olMail
Set objNS = Application.GetNamespace("MAPI")
Set objInbox = objNS.GetDefaultFolder(olFolderInbox)
On Error Resume Next
Set objFolder = objInbox.Folders("Undelivered E-Mails")
'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
Set Item = Application.ActiveExplorer.Selection(1)
Set Folder = objInbox.Folders("Undelivered E-Mails")
Item.Move Folder
Next
Set objItem = Nothing
Set objFolder = Nothing
Set objInbox = Nothing
Set objNS = Nothing
End Sub
 

Diane Poremsky

Senior Member
Outlook version
Outlook 2016 32 bit
Email Account
Office 365 Exchange
That looks like what larry suggested. :)

you need to use the for each in the selection from the original code, or just remove the if statements from it.

For Each ObjItem In Application.ActiveExplorer.Selection
ObjItem.Move objFolder
Next
 

LMS

Senior Member
Outlook version
Email Account
Exchange Server
That looks like what larry suggested. :)

you need to use the for each in the selection from the original code, or just remove the if statements from it.

For Each ObjItem In Application.ActiveExplorer.Selection
ObjItem.Move objFolder
Next

I don't understand what to actually change...can you give me the exact thing to add and where and what to delete?
 

Diane Poremsky

Senior Member
Outlook version
Outlook 2016 32 bit
Email Account
Office 365 Exchange
this is your original code with the lines checking the item type removed - the code you posted from the ms forum is messy - messier than even some of my code. :)

if this worked for a selection of email it will work for a selection of anything with the lines checking the class removed.

Code:
Sub MoveSelectedMessagesToFolderUndeliveredEmails() 
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("Undelivered E-Mails") 
'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 
    ObjItem.Move objFolder 
Next 
 
Set ObjItem = Nothing 
Set objFolder = Nothing 
Set objInbox = Nothing 
Set objNS = Nothing 
End Sub
 

LMS

Senior Member
Outlook version
Email Account
Exchange Server
I copied and pasted and tested what you just posted and it did nothing....sorry!!
 

Diane Poremsky

Senior Member
Outlook version
Outlook 2016 32 bit
Email Account
Office 365 Exchange
the last code i posted works perfectly here. Step into the code and see what it does.
 

LMS

Senior Member
Outlook version
Email Account
Exchange Server
I don't know what you said to review the code
 
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
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
I Automating message move between folders Outlook VBA and Custom Forms 0
K Outlook Rules: Move a Copy Using Outlook 4
K VBA BeforeItemMove event create rule to always move to its folder. Outlook VBA and Custom Forms 4
N Move emails of same conversation to same subfolder Using Outlook 6
Peter H Williams How to Move Mail item after processing Outlook VBA and Custom Forms 5
D Move Emails between Folders in Separate Mailbox Outlook VBA and Custom Forms 12
E Search for folder by key in subject then move new message to related folder Outlook VBA and Custom Forms 1
I Outlook 2013 Any way to move .OST file to new system? Using Outlook.com accounts in Outlook 5
O On click,I want to change subject line of selected mail and then reply to particular email and move Using Outlook 3
F "Move to" O365 feature to Outlook client via VBA Outlook VBA and Custom Forms 4
B Macro to manually move selected emails to network folder Outlook VBA and Custom Forms 1

Similar threads

Top