1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38
| Option Explicit
Option Compare Text
Sub Essai()
Extraction "Test", "mimi@provider.fr"
End Sub
Sub Extraction(NomDossier As String, Expediteur As String)
Dim olApp As Outlook.Application
Dim olSpace As Outlook.Namespace
Dim olFolder As Outlook.MAPIFolder
Dim olInbox As Outlook.MAPIFolder
Dim olmail As Outlook.MailItem
Dim pceJointe As Outlook.Attachment
Dim y As Integer, x As Integer
Set olApp = New Outlook.Application
Set olSpace = olApp.GetNamespace("MAPI")
Set olInbox = olSpace.GetDefaultFolder(olFolderInbox)
Set olFolder = olInbox.Folders(NomDossier)
For Each olmail In olFolder.Items
If olmail.SenderEmailAddress = Expediteur And _
Not olmail.Attachments.Count = 0 Then
For y = 1 To olmail.Attachments.Count
Set pceJointe = olmail.Attachments(y)
x = x + 1
pceJointe.SaveAsFile "C:\" & x & "_" & pceJointe
Set pceJointe = Nothing
Next y
End If
Next olmail
End Sub |
Partager