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
| Sub extrait_PJ_vers_rep(strID As Outlook.MailItem)
' ***olivier CATTEAU***
' 23 avril 2007
Dim olNS As Outlook.namespace
Dim MyMail As Outlook.MailItem
Dim expediteur
Set olNS = Application.GetNamespace("MAPI")
Set MyMail = olNS.GetItemFromID(strID.EntryID)
'MsgBox "nouveau message"
If MyMail.Attachments.Count > 0 Then
expediteur = MyMail.SenderEmailAddress
'on crée le répertoire où mettre les fichiers joints ##########################################################
Repertoire = "L:\CHARANTELEC\Gestion outil\"
If Repertoire <> "" Then
If "" = Dir(Repertoire, vbDirectory) Then
MkDir Repertoire
End If
End If
'on traite les pj
Dim PJ, typeatt
For Each PJ In MyMail.Attachments
'vérification si c'est une PJ Embedded
If "" <> Dir(Repertoire & PJ.FileName, vbNormal) Then
MsgBox Repertoire & PJ.FileName & " existe !!"
'si existe copie vers le répertoire old
If "" = Dir(Repertoire & "old", vbDirectory) Then
MkDir Repertoire & "old"
End If
FileCopy Repertoire & PJ.FileName, Repertoire & "old\" & PJ.FileName
End If
PJ.SaveAsFile Repertoire & PJ.FileName
Next PJ
'cette partie là aussi est optionnelle
'Marque lu
MyMail.UnRead = False
MyMail.Save
End If
Set MyMail = Nothing
Set olNS = Nothing
Fin:
End Sub |
Partager