Consulting

Results 1 to 3 of 3

Thread: VBA Move Emails from one folder to specific Folder

  1. #1

    VBA Move Emails from one folder to specific Folder

    Guys, I have cobbled together the below code to move emails from one folder to another. I attached my code and original message it won't let me paste here.


    Thank you,
    Attached Files Attached Files

  2. #2
    Assuming that you are running this macro fro Outlook, you don't need to create a new Outlook instance. Use the active one.
    You haven't told the macro what objItem is.
    Assuming your paths are correct the following should work and I see nothing wrong with the line in question

    Sub MoveDraftMail()
    
    Dim objNamespace As Outlook.NameSpace
    Dim objSourceFolder As Outlook.MAPIFolder
    Dim objDestFolder As Outlook.MAPIFolder
    Dim objItem As Object
    Dim Archive_Folder As Outlook.MAPIFolder
    
    
        Set objNamespace = Application.GetNamespace("MAPI")
        Set objSourceFolder = objNamespace.folders(10).folders("HouseBillofLadingReport")
        Set Archive_Folder = objNamespace.folders("Online Archive - My@email").folders("Personal_Folders").folders("2021").folders("InBox")
        For Each objItem In objSourceFolder.items
            If TypeName(objItem) = "MailItem" Then
                objItem.Move Archive_Folder
            End If
            DoEvents
        Next objItem
        Set objDestFolder = Nothing
        Set objNamespace = Bothing
        Set objSourceFolder = Nothing
        Set Archive_Folder = Nothing
        Set objItem = Nothing
    End Sub
    Graham Mayor - MS MVP (Word) 2002-2019
    Visit my web site for more programming tips and ready made processes
    http://www.gmayor.com

  3. #3
    Gmayor....you nailed it. Thank you!

Posting Permissions

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