'++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
'++ PROCEDURE POUR EXPORTER LES PIECES JOINTES VERS DIFFERENTS REPERTOIRES
'++
'++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
'---------------------------------------------------------------------------------------------------
Private Sub Application_NewMail()
'Declaration
Dim myItems, myItem, myAttachments, myAttachment As Object
Dim myOrt As String
Dim myOlApp As New Outlook.Application
Dim myOlExp As Outlook.Explorer
Dim myOlSel As Outlook.Selection
Dim i As Integer
'Boîte de dialogue simple pour le chemin de sauvegarde
On Error Resume Next
'Actions sur les objets sélectionnés
Set myOlExp = myOlApp.ActiveExplorer
Set myOlSel = myOlExp.Selection
'boucle pour tous les mails
For Each myItem In myOlSel
Set myAttachments = myItem.Attachments
If myAttachments.Count > 0 Then
'for all attachments do... For i = 1 To myAttachments.Count
'========== ENREGISTREMENTS VERS DOSSIERS DE DESTINATION
'========== SPECIFIQUES SELON TYPE DE PIECES JOINTES
If UCase(Right(objMessage.Attachments.Item(i).FileName, 3)) = "csv" Then
objMessage.Attachments.Item(i).SaveAsFile "D:\csv\ & _"
objMessage.Attachments.Item(i).FileName
If "" = Dir("D:\csv\") Then MkDir ("D:\csv\")
If UCase(Right(objMessage.Attachments.Item(i).FileName, 3)) = "pdf" Then
objMessage.Attachments.Item(i).SaveAsFile "D:\pdf\ & _"
objMessage.Attachments.Item(i).FileName
If "" = Dir("D:\pdf\") Then MkDir ("D:\pdf\")
If UCase(Right(objMessage.Attachments.Item(i).FileName, 3)) = "doc" Then
objMessage.Attachments.Item(i).SaveAsFile "D:\doc\ & _"
objMessage.Attachments.Item(i).FileName
If "" = Dir("D:\doc\") Then MkDir ("D:\doc\")
If UCase(Right(objMessage.Attachments.Item(i).FileName, 3)) = "xls" Then
objMessage.Attachments.Item(i).SaveAsFile "D:\xls\ & _"
objMessage.Attachments.Item(i).FileName
If "" = Dir("D:\xls\") Then MkDir ("D:\xls\")
End If
End If
End If
End If
'===== Ajoute une remarque dans le corps du message qui signale suppresssion pièce jointe
myItem.Body = myItem.Body & vbCrLf & "pièce jointe enlevée et archivée sous:" _
& ("D:\csv\ou pdf ou doc ou xls") & "-nom fichier-" & myAttachments(i).DisplayName & vbCrLf
Next i
'=======Enlève les pièces jointes du message ' While myAttachments.Count > 0
' myAttachments(1).Delete
' Wend
'===='Sauvegarde le message sans ses pièces jointes
myItem.save
End If
Next
Set myItems = Nothing
Set myItem = Nothing
Set myAttachments = Nothing
Set myAttachment = Nothing
Set myOlApp = Nothing
Set myOlExp = Nothing
Set myOlSel = Nothing
End Sub
Partager