Consulting

Results 1 to 10 of 10

Thread: Mail movment from genric folder to subfolders

  1. #1

    Mail movment from genric folder to subfolders

    Hi all,

    I have this small requirement its E-mails movement from my Generic mail box to its sub folder as given in the below screen shot for your reference.

    Could someone advice please .

    attached is the screen shot for your reference .
    Attached Images Attached Images

  2. #2
    VBAX Mentor skatonni's Avatar
    Joined
    Jun 2006
    Posts
    347
    Location
    This demonstrates how to reference a non-default inbox.

    Option Explicit
    
    Private Sub MoveToFolder()
        
        Dim myInbox As Folder
        Dim myDestFolder As Folder
        
        Dim myItem As mailItem
        
        Set myInbox = Session.Folders("CFS-NAPA")
        Set myInbox = myInbox.Folders("Inbox")  ' Not the default olFolderInbox
    
        Set myDestFolder = myInbox.Folders("Name of folder under the red line")
        Set myDestFolder = myDestFolder.Folders("Printed")
            
        Set myItem = ActiveExplorer.Selection.Item(1)
        Debug.Print myItem.Subject
        
        myItem.Move myDestFolder
        
        Set ActiveExplorer.CurrentFolder = myDestFolder
        
    ExitRoutine:
        Set myInbox = Nothing
        Set myDestFolder = Nothing
        Set myItem = Nothing
        
    End Sub
    To debug, mouse-click anywhere in the code. Press F8 repeatedly to step through the code. http://www.cpearson.com/excel/DebuggingVBA.aspx

    If your problem has been solved in your thread, mark the thread "Solved" by going to the "Thread Tools" dropdown at the top of the thread. You might also consider rating the thread by going to the "Rate Thread" dropdown.

  3. #3
    Hi Skatonni,

    Thanks for your inputs on my request this is something I have been looking .

    Hope code works fine , i did not test it because, before I execute this I need little dynamic , my apologies I should have said this before .

    Code movies E-mails to destined folder as given but I wanted those E-mails to be moved to my destined folder when criteria met let’s say .

    I wanted those mails with text inside the PDF attachment saying .

    1. X7 below $250 to be moved to printed mail box
    2. XB below $250 to be moved to printed mail box



    Attached are the screen shot for your reference .let me know if you want anything else.
    Attached Images Attached Images

  4. #4
    VBAX Mentor skatonni's Avatar
    Joined
    Jun 2006
    Posts
    347
    Location
    I believe your question was answered. The addendum may not be answerable. Try a new question with an appropriate subject. Link to this one if you think it would help.
    To debug, mouse-click anywhere in the code. Press F8 repeatedly to step through the code. http://www.cpearson.com/excel/DebuggingVBA.aspx

    If your problem has been solved in your thread, mark the thread "Solved" by going to the "Thread Tools" dropdown at the top of the thread. You might also consider rating the thread by going to the "Rate Thread" dropdown.

  5. #5
    Hi mate .. yes it was in fact answered by you .. ok if you say so i will raise another question on my Addendum..

    thanks for your help in this regards.

  6. #6
    Hi mate ,

    I have tested the code ,it is giving me error lets say. I have changed my destination folder to "Cases to be Raised" from "printed"
    below is the code for your reference .

    My source folder is now (CFS-NAPA) inbox to subfolder (cases to be raised).

    can you please look into this


    Option Explicit 
     
    Private Sub MoveToFolder() 
         
        Dim myInbox As Folder 
        Dim myDestFolder As Folder 
         
        Dim myItem As mailItem 
         
        Set myInbox = Session.Folders("CFS-NAPA") 
        Set myInbox = myInbox.Folders("Inbox") ' Not the default olFolderInbox
         
        Set myDestFolder = myInbox.Folders("Name of folder under the red line") ==== here what folder name ideally I should be adding in .
        Set myDestFolder = myDestFolder.Folders("Printed") 
         
        Set myItem = ActiveExplorer.Selection.Item(1) 
        Debug.Print myItem.Subject 
         
        myItem.Move myDestFolder 
         
        Set ActiveExplorer.CurrentFolder = myDestFolder 
         
    ExitRoutine: 
        Set myInbox = Nothing 
        Set myDestFolder = Nothing 
        Set myItem = Nothing 
         
    End Sub
    Attached Images Attached Images
    Last edited by Hudson; 01-11-2017 at 09:11 AM. Reason: attched screen shot

  7. #7
    VBAX Mentor skatonni's Avatar
    Joined
    Jun 2006
    Posts
    347
    Location
    Follow the path the same as if you were opening the tree manually.

    Option Explicit 
     
    Private Sub MoveToFolder() 
         
        Dim myInbox As Folder 
        Dim myDestFolder As Folder 
         
        Dim myItem As mailItem 
         
        Set myInbox = Session.Folders("CFS-NAPA") 
        Set myInbox = myInbox.Folders("Inbox")
         
        Set myDestFolder = myInbox.Folders("Cases to be Raised") 
         
        Set myItem = ActiveExplorer.Selection.Item(1) 
        Debug.Print myItem.Subject 
         
        myItem.Move myDestFolder 
         
        Set ActiveExplorer.CurrentFolder = myDestFolder 
         
    ExitRoutine: 
        Set myInbox = Nothing 
        Set myDestFolder = Nothing 
        Set myItem = Nothing 
         
    End Sub
    To debug, mouse-click anywhere in the code. Press F8 repeatedly to step through the code. http://www.cpearson.com/excel/DebuggingVBA.aspx

    If your problem has been solved in your thread, mark the thread "Solved" by going to the "Thread Tools" dropdown at the top of the thread. You might also consider rating the thread by going to the "Rate Thread" dropdown.

  8. #8
    Hi mate , I know I am asking for too much , can you take me through the code please , out of your busy time .

  9. #9
    mat can we Disable events and let it be just sub program . because I want to run manually with my interest.
    sorry for giving you trouble ..

  10. #10
    VBAX Mentor skatonni's Avatar
    Joined
    Jun 2006
    Posts
    347
    Location
    This code is to be run manually. First select a mailitem. No need to open it. The selection will be used in

    Set myItem = ActiveExplorer.Selection.Item(1)
    With this line there is no need to reference a Source folder. Note only one item is processed any more are ignored.

    To reference the destination folder, the code walks its way from the top of the folder tree to the destination folder.

    Set myInbox = Session.Folders("CFS-NAPA") 
    Set myInbox = myInbox.Folders("Inbox") 
         
    Set myDestFolder = myInbox.Folders("Cases to be Raised")

    This moves the selected item

    myItem.Move myDestFolder
    This displays the destination folder. It is not necessary.

    Set ActiveExplorer.CurrentFolder = myDestFolder
    To debug, mouse-click anywhere in the code. Press F8 repeatedly to step through the code. http://www.cpearson.com/excel/DebuggingVBA.aspx

    If your problem has been solved in your thread, mark the thread "Solved" by going to the "Thread Tools" dropdown at the top of the thread. You might also consider rating the thread by going to the "Rate Thread" dropdown.

Posting Permissions

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