Option Explicit
Sub Essai()
Extraction "En attente", "a.l@gmail.com"
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 MonBody As String, MonNum As String
Dim y As Integer, x As Integer
Dim nom As Variant
Dim Argument As String
Dim sDossier As String, sFichier As String, sFeuille As String
Dim Valeurextraite As String
Set olApp = New Outlook.Application
Set olSpace = olApp.GetNamespace("MAPI")
Set OLinbox = olSpace.GetDefaultFolder(olFolderInbox)
Set olFolder = OLinbox.Folders(NomDossier)
Dim Chemin As String, Fich As String, Feuil As String, Cell As String, Result
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
sDossier = ""
sFichier = pceJointe
sFeuille = "Feuil1"
Valeurextraite = ExtraireValeur(sDossier, sFichier, sFeuille, "A1")
pceJointe.SaveAsFile "C:\Users\Desktop\" & Valeurextraite & "-" & pceJointe
Set pceJointe = Nothing
Next y
End If
Next olmail
End Sub
Private Function ExtraireValeur(ByVal Dossier As String, ByVal Fichier As String, ByVal Feuille As String, ByVal Cellule As String)
Dim Argument As String
Argument = "'" & Dossier & "[" & Fichier & "]" & Feuille & "'!" & "R1C1"
ExtraireValeur = ExecuteExcel4Macro(Argument)
End Function