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 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103
| Sub test_Item()
Dim Item As Outlook.MailItem
Set Item = ActiveInspector.CurrentItem
SaveFS Item
End Sub
Sub SaveFS(Item As Outlook.MailItem)
Set attachs = Item.Attachments
For Each attach In attachs
Dim fso, F, sExt
Set fso = CreateObject("Scripting.FileSystemObject")
'pour obtenir le nom du fichier sans l'extension
F = fso.GetBaseName(attach.FileName)
'pour obtenir l'extension
sExt = fso.GetExtensionName(attach.FileName)
'on nomme avec le SUJET et on ajoute l'extension du fichier
FILE = remplaceCaracteresInterdit(Item.Subject) & "." & sExt
'on vérifie que le dossier existe et sinon on le créé
Dim sdossier
sdossier = "C:\Users\sloang\Plannings " & Format(RegExDate(Item.Subject), "dd.mm.yyyy")
sdossier = "C:\TEMP\A ENVOYER\Plannings " & Format(RegExDate(Item.Subject), "dd.mm.yyyy")
Call waaps_creedir(CStr(Dossier))
attach.SaveAsFile sdossier & "\" & FILE
Next
End Sub
Function remplaceCaracteresInterdit(ByVal CheminStr As String)
Dim objCurrentMessage As Outlook.MailItem
Dim Liste As Variant
Dim L
Liste = Array("\", "/", ":", "*", "?", "<", ">", "|", ".", """", vbTab, Chr(7))
For L = 0 To UBound(Liste)
CheminStr = Replace(CheminStr, Liste(L), "")
Next L
remplaceCaracteresInterdit = CheminStr
'MsgBox CheminStr
End Function
Private Function waaps_creedir(lerep As String) As Boolean
'----------------------------------------------------------------------
' FUNCTION : waaps_creedir
' Création d'un répertoire (récursif)
'----------------------------------------------------------------------
' Paramètres :
' rep : répertoire à créer par son chemin relatif % au root
'----------------------------------------------------------------------
' retour : True si le répertoire est créé
'----------------------------------------------------------------------
' Global utilisé : REP_TOP
'----------------------------------------------------------------------
' COPYRIGHTS : 1994-2005 CAXTON / WAAPS / BRUNO VILLACAMPA
' Utilisation commerciale interdite
' Utilisation personnelle / professionnelle autorisée
' Le message courant doit être préservé
'----------------------------------------------------------------------
On Error Resume Next
Dim fso As Object, i As Integer, retour As Boolean
Dim rp As String, r
Dim rep, REP_TOP
Set fso = CreateObject("Scripting.filesystemobject")
rp = Replace(lerep, "\", "/")
rp = Replace(rp, "//", "/")
rep = Split(rp, "/")
r = REP_TOP
retour = True
For i = 0 To UBound(rep)
If (rep(i) <> "") Then
r = r & rep(i) & "\"
If (Not fso.FolderExists(r)) Then
fso.CreateFolder (CStr(r))
If (Not fso.FolderExists(r)) Then retour = False
End If
End If
Next
Set fso = Nothing
waaps_creedir = retour
End Function
Private Function RegExDate(s As String) As String
Dim re, match
Set re = CreateObject("vbscript.regexp")
re.Pattern = "(0[1-9]|[12][0-9]|3[01])[- /.](0[1-9]|1[012])[- /.](19|20)[0-9]{2}"
re.Global = True
For Each match In re.Execute(s)
'MsgBox match.Value
RegExDate = match.Value
Exit For
Next
Set re = Nothing
End Function |
Partager