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
|
Option Explicit
Private oShell As Object
Private Save_To_Folder As Object
Private MonRepertoire As String
Sub Sav_Mail_As_Msg_Modifie(ByVal Repertoire As String, Optional ObjCurrentMessage As Object)
Dim NomExport As String, PathNomExport As String, Annee As String, Mois As String, Jour As String, Heure As String, MemPath As String
Dim N As Integer
'Dim oShell As Object
'Dim Save_To_Folder As Object
' Set oShell = CreateObject("Shell.Application")
If ObjCurrentMessage Is Nothing Then Set ObjCurrentMessage = ActiveInspector.CurrentItem
'Extraction et formatage de la date
Annee = Mid(ObjCurrentMessage.CreationTime, 7, 4)
Mois = Mid(ObjCurrentMessage.CreationTime, 4, 2)
Jour = Mid(ObjCurrentMessage.CreationTime, 1, 2)
Heure = Mid(ObjCurrentMessage.CreationTime, 12, 5)
'Ici on construit le nom du fichier qui sera créé
With ObjCurrentMessage
NomExport = Annee & "-" & Mois & "-" & Jour & "-" & Heure & "-" & " " & .Subject & "-" & .SenderName
End With
'Ici on défini le répertoire où l'enregistrer
'repertoire = "c:\temp\"
'Ici on supprime les caractères non autorisé dans les noms de fichiers
PathNomExport = Repertoire & Left(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace( _
NomExport, "\", " "), "/", " "), ":", ""), "*", " "), "?", " "), "<", " "), ">", " "), "|", " "), ".", " "), """", ""), vbTab, ""), Chr(7), ""), 160) & ".msg"
'Ici on vérifie que le fichier n'existe pas déjà sinon il serait écrasé
N = 1
MemPath = PathNomExport
While Dir(PathNomExport) <> ""
MsgBox "Le fichier " & vbCr & PathNomExport & vbCr & "existe déjà", vbInformation
PathNomExport = Left(MemPath, Len(MemPath) - 4) & "(" & N & ")" & ".msg"
N = N + 1
Wend
ObjCurrentMessage.SaveAs PathNomExport, OlSaveAsType.olMSG
End Sub
Sub LanceSurOuvert()
Set oShell = CreateObject("Shell.Application")
Set Save_To_Folder = oShell.browseforfolder(0, "Séléctionner dossier d'archivage:", 1)
If Save_To_Folder Is Nothing Then Exit Sub
MonRepertoire = Save_To_Folder.ParentFolder.ParseName(Save_To_Folder.Title).Path & "\"
Sav_Mail_As_Msg_Modifie MonRepertoire
RangerMailCategory
Set oShell = Nothing
Set Save_To_Folder = Nothing
End Sub
Sub LanceSurSelection()
Dim MonOutlook As Outlook.Application
Dim LeMail As Object
Dim LesMails As Outlook.Selection
Set MonOutlook = Outlook.Application
Set LesMails = MonOutlook.ActiveExplorer.Selection
Set oShell = CreateObject("Shell.Application")
Set Save_To_Folder = oShell.browseforfolder(0, "Séléctionner dossier d'archivage:", 1)
If Save_To_Folder Is Nothing Then Exit Sub
MonRepertoire = Save_To_Folder.ParentFolder.ParseName(Save_To_Folder.Title).Path & "\"
For Each LeMail In LesMails
Sav_Mail_As_Msg_Modifie MonRepertoire, LeMail
Next LeMail
Set LesMails = Nothing
'MsgBox "Votre mail a été archivé"
RangerMailCategory
Set oShell = Nothing
Set Save_To_Folder = Nothing
Set MonOutlook = Nothing
End Sub |
Partager