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 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292
| Public Bckup As Outlook.Folder
Sub test_this()
Dim objitem As Object
Set objitem = ActiveInspector.CurrentItem
Set BTR = objitem.Application.Session.GetDefaultFolder(olFolderInbox)
Set Bckup = BTR.folders("Test")
ProcessThisItem objitem
End Sub
Sub Lance_Traitement()
'---------------------------------------------------------------------------------------
' Procedure : Lance_Traitement
' Author : Oliv
' Date : 12/02/2016
' Purpose :
'---------------------------------------------------------------------------------------
'
Dim OL As Outlook.Application
Dim olNS As Outlook.NameSpace
Dim olFolder As Outlook.Folder
Dim objfolder As Outlook.MAPIFolder
Set OL = Outlook.Application
Set olNS = OL.GetNamespace("MAPI")
'soit on le choisi
' Set olFolder = olNS.PickFolder
'Pour les dossiers EMBARGO
Set olFolder = olNS.folders("EMBARGO Securite-Financiere")
' Set objfolder = objfolder.Store.GetDefaultFolder(olFolderInbox)
Set objfolder = olFolder.folders("EMBARGO")
Call ProcessFolders(objfolder, True)
Set BTR = olFolder.folders("Boîte de réception")
Set Bckup = BTR.folders("Bckup Macro")
'Pour les dossiers CACIB
Set olFolder = olNS.folders("EMBARGOCACIB Ddc")
Call ProcFolders(olFolder, True)
Set BTR = olFolder.folders("Boîte de réception")
Set Bckup = BTR.folders("Bckup Macro")
'Pour les dossiers LCL
Set olFolder = olNS.folders("EMBARGOLCL Ddc")
Call ProcFolders(olFolder, True)
Set BTR = olFolder.folders("Boîte de réception")
Set Bckup = BTR.folders("Bckup Macro")
MsgBox "Traitement terminé"
End Sub
Sub ProcessFolders(StartFolder As Outlook.MAPIFolder, SubFolder As Boolean)
'---------------------------------------------------------------------------------------
' Procedure : ProcessFolder
' Author : Oliv'
' Date : 12/02/2016
' Purpose : Traitement récursif sur les dossiers OUTLOOK
'---------------------------------------------------------------------------------------
'
Dim objfolder As Outlook.MAPIFolder
Dim objitem As Object
'Dim objItem As Object
On Error Resume Next
' do something specific with this folder
Debug.Print StartFolder.FolderPath, StartFolder.Count
Debug.Print
For Each objfolder In StartFolder.folders
If StartFolder.DefaultItemType = olMailItem Then
' ICI LE TRAITEMENT POUR CHAQUE DOSSIER
'Call ProcessThisFolder(StartFolder)
End If
' process all the items in this folder
'ICI LE TRAITEMENT POUR TOUS LES ELEMENTS DU DOSSIER
Dim i
Dim j
i = objfolder.Items.Count
If i <> 0 Then
For j = 1 To i
Set objitem = objfolder.Items(j)
Call ProcessThisItem(objitem)
Next j
End If
Next
' process all the subfolders of this folder
'on traite tous les sous dossiers
If SubFolder Then
Call ProcessFolders(objfolder, SubFolder)
End If
Set objfolder = Nothing
End Sub
Sub ProcessThisItem(objitem As Object)
'---------------------------------------------------------------------------------------
' Procedure : ProcessThisItem
' Author : Oliv
' Date : 12/02/2016
' Purpose :
'---------------------------------------------------------------------------------------
Dim Nomdossier
Dim OL As Outlook.Application
Dim olNS As Outlook.NameSpace
Dim olFolder As Outlook.Folder
Dim BTR As Outlook.MAPIFolder
Dim FolderToMove As Outlook.Folder
Dim oMail As Outlook.MailItem
'
If objitem.Class = olMail Then
Dim mymail As Outlook.MailItem
Set mymail = objitem
Nomdossier = mymail.Parent.Name
If InStr(1, mymail.Body, "libéré", vbTextCompare) Or InStr(1, mymail.Body, "annulé", vbTextCompare) Or InStr(1, mymail.Body, "libération", vbTextCompare) Or InStr(1, mymail.Body, "released", vbTextCompare) Or InStr(1, mymail.Body, "annulation", vbTextCompare) Then
If mymail.CreationTime < DateAdd("d", -60, Date) Then
Call SaveandMoveConversation(mymail, Bckup, "O:\Projets01\DDC-CC\EMBARGO\" & Nomdossier & "\2016")
' Set OL = Outlook.Application
' Set olNS = OL.GetNamespace("MAPI")
' Set olFolder = olNS.Folders("EMBARGO Securite-Financiere")
' Set BTR = olFolder.Folders("Boîte de réception")
' Set Bckup = BTR.Folders("Bckup Macro")
' Call MoveConversation(mymail, Bckup)
' mymail.Move Bckup
End If
End If
End If
End Sub
Sub SavAs_mail_as_msg(mymail As Outlook.MailItem, repertoire)
'---------------------------------------------------------------------------------------
' Procedure : SavAs_mail_as_msg
' Author : Oliv
' Date : 12/02/2016
' Purpose :
'---------------------------------------------------------------------------------------
'
' exemple repertoire = "c:\mail\"
Dim NomExport
Dim PathNomExport
Dim n
Dim MemPath
'Ici on construit le nom du fichier qui sera créé
NomExport = mymail.subject
' & mymail.CreationTime
'Ici on vérifie le répertoire où l'enregistrer
If Right(repertoire, 1) <> "\" Then repertoire = repertoire & "\"
'on vérifie s'il existe sinon on le crée
Module10.waaps_creedir (repertoire)
'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
mymail.SaveAs PathNomExport, OlSaveAsType.olMSG
Call ModifDate(CStr(PathNomExport), mymail.CreationTime, 4)
Call refresh_explorer(PathNomExport)
End Sub
Sub ProcFolders(StartFolder As Outlook.MAPIFolder, SubFolder As Boolean)
'---------------------------------------------------------------------------------------
' Procedure : ProcFolder
' Author : Oliv'
' Date : 12/02/2016
' Purpose : Traitement récursif sur les dossiers OUTLOOK
'---------------------------------------------------------------------------------------
'
Dim objfolder As Outlook.MAPIFolder
Dim objitem As Object
'Dim objItem As Object
On Error Resume Next
' do something specific with this folder
Debug.Print StartFolder.FolderPath, StartFolder.Count
Debug.Print
If StartFolder.DefaultItemType = olMailItem Then
' ICI LE TRAITEMENT POUR CHAQUE DOSSIER
'Call ProcessThisFolder(StartFolder)
End If
' process all the items in this folder
'ICI LE TRAITEMENT POUR TOUS LES ELEMENTS DU DOSSIER
Dim i
Dim j
i = StartFolder.Items.Count
If i <> 0 Then
For j = 1 To i
Set objitem = StartFolder.Items(j)
Call ProcessThisItem(objitem)
Next j
End If
' process all the subfolders of this folder
'on traite tous les sous dossiers
If olMailItem <> 0 Then
Call ProcFolders(objfolder, SubFolder)
End If
' Set objfolder = Nothing
End Sub
Private Sub Test_Conversation()
Dim FolderToMove As Outlook.Folder
Dim oMail As Outlook.MailItem
' Obtain the current item for the active inspector.
Set oMail = Application.ActiveInspector.CurrentItem
Set FolderToMove = Application.Session.PickFolder
Call MoveConversation(oMail, FolderToMove)
End Sub
Sub SaveandMoveConversation(oMail As Outlook.MailItem, FolderToMove As Outlook.Folder, repertoire)
'---------------------------------------------------------------------------------------
' Procedure : MoveConversation
' Author : Oliv
' Date : 18/02/2016
' Purpose : Pour déplacer une conversation
'---------------------------------------------------------------------------------------
'
Dim oConv As Outlook.Conversation
Dim oTable As Outlook.Table
Dim oRow As Outlook.Row
Dim mymail As Outlook.MailItem
Dim oItem As Outlook.MailItem
Const PR_STORE_ENTRYID As String = _
"http://schemas.microsoft.com/mapi/proptag/0x0FFB0102"
On Error Resume Next
If Not (oMail Is Nothing) Then
' Obtain the Conversation object.
Set oConv = oMail.GetConversation
If Not (oConv Is Nothing) Then
Set oTable = oConv.GetTable
oTable.Columns.add (PR_STORE_ENTRYID)
Debug.Print oTable.GetRowCount
Do Until oTable.EndOfTable
Set oRow = oTable.GetNextRow
' Use EntryID and StoreID to open the item.
Set oItem = Application.Session.GetItemFromID( _
oRow("EntryID"), _
oRow.BinaryToString(PR_STORE_ENTRYID))
Call SavAs_mail_as_msg(oItem, repertoire)
oItem.Move FolderToMove
Loop
End If
End If
End Sub |
Partager