lms
04-10-2014, 03:41 PM
I have the following code that when I select any number of emails, I can send them to a particular folder...but if the email is a report that the email I sent was not delivered or received etc., the report email that I select does not move to a particular folder. And the code from a developer has the words to do it, but it does not....so does anyone know what to change so I select a list of report emails and can move them to a folder. Thanks very much.
[CODE][Sub MoveSelectedMessagesToFolderUndeliveredEmails()
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
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
/CODE]
[CODE][Sub MoveSelectedMessagesToFolderUndeliveredEmails()
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
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
/CODE]