Option Explicit Public Declare Function MkDir Lib "imagehlp.dll" Alias "MakeSureDirectoryPathExists" (ByVal DirPath As String) As Long Public Declare Function GetFileAttributes Lib "kernel32.dll" Alias "GetFileAttributesA" (ByVal lpFileName As String) As Long Public Const INVALID_FILE_ATTRIBUTES As Long = &HFFFFFFFF Public Function DoesExist(ByRef vsPath As String) As Boolean DoesExist = (GetFileAttributes(vsPath) <> INVALID_FILE_ATTRIBUTES) End Function Public Function extrait_PJ_vers_rep(ByVal Folder As String, ByRef Mail As Outlook.MailItem) As Long Dim Attachment As Attachment Dim IsEmbedded As Boolean If Not Nothing Is Mail Then If Mail.Attachments.Count > 0 Then If Right$(Folder, 1) <> "" Then Folder = Folder & "" End If For Each Attachment In Mail.Attachments IsEmbedded = True On Local Error Resume Next '# Semble etre propre à Outlook 2007 et supérieur IsEmbedded = Attachment.Fields(&H3712001E) On Local Error GoTo 0 If IsEmbedded Then If DoesExist(Folder & Attachment.FileName) Then MkDir Folder & "ancien commande promod" FileCopy Folder & Attachment.FileName, Folder & "ancien commande promod" & Attachment.FileName Else MkDir Folder End If Attachment.SaveAsFile Folder & Attachment.FileName extrait_PJ_vers_rep = extrait_PJ_vers_rep + 1 End If Next '# Semble etre propre à Outlook 2007 et supérieur 'Mail.FlagIcon = olGreenFlagIcon Mail.UnRead = False Mail.Save End If DoEvents End If End Function Sub test() Dim Item As Object Dim nAttachments As Long Dim nCount As Long Dim nMails As Long Dim nMailsWithAttachments As Long For Each Item In Session.GetDefaultFolder(olFolderInbox).Items If TypeOf Item Is MailItem Then nMails = nMails + 1 nCount = extrait_PJ_vers_rep("C:\x", Item) If nCount Then nMailsWithAttachments = nMailsWithAttachments + 1 nAttachments = nAttachments + nCount End If End If Next MsgBox nMails & " mails lus." & vbNewLine & _ nAttachments & " pièces jointes archivées, réparties dans " & nMailsWithAttachments & " mails.", vbInformation End Sub
Vous n’avez pas trouvé la réponse que vous recherchez ?
Posez votre questionPublic Function extrait_PJ_vers_rep(ByVal Folder As String, ByRef Mail As Outlook.MailItem) As Long
Public Function extrait_PJ_vers_rep(ByRef Mail As Outlook.MailItem) As Long Dim Folder As String : Folder = "E:\x"