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
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
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.
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
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
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
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.