none
Change VBA Script to move the mail to another folder. OUTLOOK 2010 RRS feed

  • Question

  • Hello

    I have a script that saves xml files and performs this email forwarding automatically if there is an xml and pdf file.

    I would like in this same script, after forwarding, to move this email to this email to a folder called "archived" and mark it as read.

    I made a code for it, but it's not working.

    The code processes for 1 minute as it has the code to be moved, it does not move the email and finally moves to the end of the code.


    Can someone help me?

    Public Sub ProcessarAnexo(email As MailItem)
        Dim DiretorioAnexos As String
        DiretorioAnexos = "C:\Users\gabriel\Documents\xml\"
    
        Dim MailID As String
        Dim Mail As Outlook.MailItem
         
        MailID = email.EntryID
        Set Mail = Application.Session.GetItemFromID(MailID)
     
        flagXML = False
        flagPDF = False
    
        For Each anexo In Mail.Attachments
        
            If Right(anexo.FileName, 3) = "xml" Or Right(anexo.FileName, 3) = "XML" Then
                flagXML = True
                anexo.SaveAsFile DiretorioAnexos & anexo.FileName
            End If
            
            If Right(anexo.FileName, 3) = "pdf" Or Right(anexo.FileName, 3) = "PDF" Then
                flagPDF = True
            End If
            
        Next
        
         Dim ForWardMail As Outlook.MailItem
        
        If (flagXML And flagPDF) Then
            Set ForWardMail = Mail.Forward
            With ForWardMail
            .Recipients.Add "alex@a.com.br"
            .Recipients.Add "paulo@a.com.br"
            .Send
            End With
    
    'MAIL MOVE
    
        Mail.Move (Application.GetNamespace("MAPI").GetDefaultFolder(olFolderInbox).Folders("Archived"))
        
        End If
    
        
        Set Mail = Nothing
    End Sub

    Friday, August 2, 2019 1:42 PM

All replies

  • Hi Gabriel,

    Welcome to our forum. Here we mainly focus on general issues about Outlook desktop client. Considering that your question is more related VBA for Outlook, so I will help you move this thread to a more dedicated appropriate forum.

    The reason why we recommend posting appropriately is you will get the most qualified pool of respondents, and other partners who read the forums regularly can either share their knowledge or learn from your interaction with us. Thanks for your understanding and hope your question will be resolved soon.

    Regards,

    Aidan Wang


    Please remember to mark the replies as answers if they helped. If you have feedback for TechNet Subscriber Support, contact tnsf@microsoft.com.

    Monday, August 5, 2019 2:45 AM