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 Classe_Prestations()
'---------------------------------------------------------------------------------------
' Procedure : Classe_Prestations
' Author : OCTU
' Date : 11/01/2016
' Purpose : Classe Les Emails dans le dossier si le sujet contient la structure []
'---------------------------------------------------------------------------------------
'
Dim MonOutlook As Outlook.Application
Dim Item As Object
Dim LeMail As Outlook.MailItem
Dim LesMails As Object
Set MonOutlook = Outlook.Application
Set LesMails = MonOutlook.ActiveExplorer.Selection
Dim objFolderDestination As MAPIFolder
For Each Item In LesMails
If Item.Class = olMail Then
Set LeMail = Item
Dim DossierName, StructureDossierName
StructureDossierName = "["
DossierName = getDossierName(Item.Subject, StructureDossierName)
If InStr(1, Item.Subject, DossierName, vbTextCompare) Then
Set objFolderDestination = getDestinationFolder("Diffusion", DossierName)
Item.Move objFolderDestination
End If
End If
Next
fin:
End Sub
Function getDestinationFolder(ParentName, FolderName) As Folder
'---------------------------------------------------------------------------------------
' Procedure : getDestinationFolder
' Author : OCTU
' Date : 03/04/2015
' Purpose : Renvoi le sous dossier d'un dossier avec création
'---------------------------------------------------------------------------------------
'
Dim objNS As NameSpace
Dim objFolderParent As MAPIFolder
Dim objFolderDestination As MAPIFolder
On Error Resume Next
Set objNS = Application.GetNamespace("MAPI")
Set objFolderParent = objNS.GetDefaultFolder(olFolderInbox).folders(ParentName)
If TypeName(objFolderParent) = "Nothing" Then
Set objFolderParent = objNS.GetDefaultFolder(olFolderInbox).folders.add(ParentName)
End If
Set objFolderDestination = objFolderParent.folders(FolderName)
If TypeName(objFolderDestination) = "Nothing" Then
Set objFolderDestination = objFolderParent.folders.add(FolderName)
End If
Set getDestinationFolder = objFolderDestination
End Function
Function getDossierName(Subject, Structure) As String
'---------------------------------------------------------------------------------------
' Procedure : getDossierName
' Author : OCTU
' Date : 03/04/2015
' Purpose : Trouve dans le sujet le nom qui correspond au début #XM
'---------------------------------------------------------------------------------------
'
OuCommenceAdresse = InStr(1, Subject, Structure, vbTextCompare)
If OuCommenceAdresse > 0 Then
fin = InStr(OuCommenceAdresse + Len(Structure), Subject, "]", vbTextCompare)
If fin = 0 Then
getDossierName = Mid(Subject, OuCommenceAdresse)
Else
getDossierName = Mid(Subject, OuCommenceAdresse + Len(Structure), fin - OuCommenceAdresse - 1)
End If
End If
End Function |
Partager