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
| Option Explicit
Public myNewFolder As Outlook.MAPIFolder
Public Tour As Double
Public olApp As Object
Sub Copie_vers_autres_bal()
Dim objFolder As Outlook.MAPIFolder
Dim strFileName As String
Dim strDisplayName As String
Dim objNS As Namespace
Dim qCreatePST, go
Set olApp = Outlook.Application
Set objNS = olApp.GetNamespace("MAPI")
MsgBox "selectionnez le dossier SOURCE"
Set objFolder = objNS.PickFolder
MsgBox "selectionnez le dossier DESTINATION"
Set myNewFolder = objNS.PickFolder
If MsgBox("Etes vous sûr de vouloir copier les éléments des dossiers et sous-dossiers de " & vbCr & objFolder.Name & vbCr & " vers " & vbCr & myNewFolder.Name, vbYesNo, "Confirmation") = vbNo Then Exit Sub
ProcessFolderCopy objFolder
MsgBox "Terminé"
End Sub
Sub ProcessFolderCopy(StartFolder As Outlook.MAPIFolder)
Dim destFolder As Outlook.Folder
Dim myItem
Dim myCopiedItem
Tour = Tour + 1
Dim objFolder As Outlook.MAPIFolder
'Dim objItem As Object
On Error Resume Next
' do something specific with this folder
Debug.Print StartFolder.FolderPath, StartFolder.Folders.Count, StartFolder.Items.Count
Debug.Print
'on teste si on est à la racine de la BAL
If InStr(3, StartFolder.FolderPath, "\") = 0 Then GoTo racine
If StartFolder.DefaultItemType = olMailItem Then
' MsgBox StartFolder.Name
Set destFolder = myNewFolder.Folders(StartFolder.Name)
On Error GoTo 0
If Not IsEmpty(destFolder) Then
For Each myItem In StartFolder.Items
If myItem.Class <> olMail And myItem.Class <> olReport Then Stop: myItem.Display
Set myCopiedItem = myItem.Copy
myCopiedItem.Move destFolder
Next myItem
For Each objFolder In StartFolder.Folders
On Error GoTo 0
Call ProcessFolderCopy(objFolder)
Next
Else
On Error Resume Next
StartFolder.CopyTo myNewFolder
Debug.Print "copy " & StartFolder.Name & " vers " & myNewFolder.Name
End If
End If
Exit Sub
racine:
' process all the subfolders of this folder
For Each objFolder In StartFolder.Folders
On Error GoTo 0
Call ProcessFolderCopy(objFolder)
Next
Set objFolder = Nothing
End Sub |
Partager