Consulting

Results 1 to 9 of 9

Thread: Outlook 2007 Move Report Email to a Folder

  1. #1
    VBAX Regular
    Joined
    Jul 2013
    Posts
    75
    Location

    Outlook 2007 Move Report Email to a Folder

    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]

  2. #2
    If objFolder.DefaultItemType = olMailItem Then
    If objItem.Class = olMail Or objItem.Class = olReport Then
    you 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

  3. #3
    VBAX Regular
    Joined
    Jul 2013
    Posts
    75
    Location
    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

  4. #4
    the latter code only moves the first item selected

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

  5. #5
    VBAX Regular
    Joined
    Jul 2013
    Posts
    75
    Location
    So delete the words: If objItem.Class = olMail Or objItem.Class = olReport Then?

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

  6. #6
    So delete the words: If objItem.Class = olMail Or objItem.Class = olReport Then?
    and end if

  7. #7
    VBAX Regular
    Joined
    Jul 2013
    Posts
    75
    Location
    I did it but it did not do it.

  8. #8
    VBAX Regular
    Joined
    Jul 2013
    Posts
    75
    Location
    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

  9. #9
    it now works perfectly
    very good

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •