PDA

View Full Version : Outlook 2007 Move Report Email to a Folder



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]

westconn1
04-11-2014, 02:42 AM
If objFolder.DefaultItemType = olMailItem Then
If objItem.Class = olMail Or objItem.Class = olReport Thenyou need to test if the unmoved reports are of class olmail or olreport, if not they will no be moved

i can not test this without a sample

lms
04-11-2014, 04:39 AM
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

westconn1
04-11-2014, 04:54 AM
the latter code only moves the first item selected


If objItem.Class = olMail Or objItem.Class = olReport Then
objItem.Move objFolder
End Ifif you remove the criteria, it should move all items selected
reduce to

objItem.Move objFolder

lms
04-11-2014, 04:59 AM
So delete the words: If objItem.Class = olMail Or objItem.Class = olReport Then?

and replace the next line with: objItem.Move objFolder ?

westconn1
04-11-2014, 05:15 AM
So delete the words: If objItem.Class = olMail Or objItem.Class = olReport Then?
and end if

lms
04-11-2014, 08:03 AM
I did it but it did not do it.

lms
04-11-2014, 08:14 AM
To All,

From a Microsoft Forum, I was told to change the objItem as a mailItem to a ReportItem and it now works perfectly and to all here is the full code that works:


Sub MoveSelectedMessagesToFolderUndeliveredEmails()
Dim objFolder As outlook.MAPIFolder, objInbox As outlook.MAPIFolder
Dim objNS As outlook.NameSpace, objItem As outlook.ReportItem
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
objItem.Move objFolder
Next
Set objItem = Nothing
Set objFolder = Nothing
Set objInbox = Nothing
Set objNS = Nothing
End Sub

westconn1
04-11-2014, 01:36 PM
it now works perfectlyvery good