Search code examples
vbaoutlookoutlook-2010

Outlook Script VBA doesn't work


I have copied this script for separate attachment from mail to a folder.

       Public Sub ProcessarAnexo(Email As MailItem)
       Dim diretorioAnex As String
       diretorioAnex = "C:\Separados"

       Dim MailID As String
       Dim mailx As Outlook.MailItem

       MailID = Email.EntryID
       Set Mail = Application.Session.GetItemFromID(MailID)

       For Each anexo In mailx.Attachments
           If Rigth(anexo.FileName, 3) = "xml" Then
           MsgBox (anexo.FileName)
           anexo.SaveAsFile directorioanex & "\" & anexo.FileName
       End If
       Next
       Set mailx = Nothing

        End Sub

I try to execute the script from "execute rules now" , but it doesn't save anything in the folder "Separados".


Solution

  • The script works , Outlook 2010 have blocked macros and code , i have enabled OutLook to run VBA and Macros and all runs fine.

    Thanks