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 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84
|
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 osa As Shell
Dim xrDec As Variant
Dim nfZip As Variant
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
' Recherche de PJ : ".xlsx", ".xlsm", ".xls", ".zip"
If Right(pceJointe, 5) = ".xlsx" Or Right(pceJointe, 4) = ".xls" Or Right(pceJointe, 4) = ".zip" Or Right(pceJointe, 5) = ".xlsm" Then
GoTo 1
Else
GoTo 2
End If
1:
' Recherche de 500 dans le corps du message
MonBody = olmail.Body
On Error Resume Next
MonNum = Mid(MonBody, InStr(1, MonBody, " 500") + 1, 8)
On Error GoTo 0
If MonNum = Empty Then
MsgBox "Numéro 500 non trouvé"
Else
' Extrait les PJ : ".xlsx", ".xlsm", ".xls"
If IsNumeric(MonNum) And Not Right(pceJointe, 4) = ".zip" Then
MsgBox "OK! C'est un N° : " & MonNum
pceJointe.SaveAsFile "C:\" & MonNum & "-" & pceJointe
Set pceJointe = Nothing
Else
' Extrait les PJ : ".zip"
If IsNumeric(MonNum) And Right(pceJointe, 4) = ".zip" Then
MsgBox "OK! C'est un N° : " & MonNum
xrDec = "C:\" 'fichier destination
nfZip = "C:\" & pceJointe 'fichier source
Set osa = New Shell
osa.NameSpace(xrDec).CopyHere osa.NameSpace(nfZip).Items
Set osa = Nothing
' En cas d'absence du numéro "500"
Else
MsgBox "KO! Ce n'est pas un N° :" & MonNum
End If
End If
End If
2:
Next y
End If
Next olmail
End Sub |
Partager