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
| Sub ImprimeTouteLaSelection_Invoke()
'---------------------------------------------------------------------------------------
' Procedure : ImprimeTouteLaSelection_Invoke
' Author : Oliv'
' Date : 12/06/2019
' Purpose :
'---------------------------------------------------------------------------------------
'
Dim MonOutlook As Outlook.Application
Dim Mail As Object
Dim LeMail As Outlook.MailItem
Dim LesMails As Object
Dim Impression As Boolean
Set MonOutlook = Outlook.Application
Set LesMails = MonOutlook.ActiveExplorer.Selection
Set Fso = CreateObject("Scripting.FileSystemObject")
DossierTemp = "C:\TEMP\PRINTtemp"
For Each LeMail In LesMails
Dim pj As Attachment
For Each pj In LeMail.Attachments
' ICI on applique des FILTRES SUR LES PJ
Select Case UCase(Fso.GetExtensionName(pj.FileName))
Case "BMP", "TIF", "PCX", "JPG", "IMG", "PCT", "PNG", "DCX", "XIF", "GIF"
Impression = True
Case "XLSX", "XLSM", "XLAM", "CSC"
Impression = False
Case "XLS"
Impression = False
Case "PDF"
Impression = True
Case Else
'ici pour tous les autres
Impression = False
End Select
If Impression Then
LeFichier = DossierTemp & "\" & pj.FileName
pj.SaveAsFile (LeFichier)
End If
Next pj
'on imprime ici
PrintFilesV2 DossierTemp, "*.*"
'on supprime les fichiers
DoEvents
On Error Resume Next
Kill DossierTemp & "\*.*"
Impression = False
Next LeMail
Set LesMails = Nothing
MsgBox "Opération terminée"
End Sub
Public Sub PrintFiles(ByRef vDir As Variant, ByRef sFileSpec As String)
Const SHCONTF_NONFOLDERS = &H40&
With CreateObject("Shell.Application")
With .Namespace(vDir).Items
.Filter SHCONTF_NONFOLDERS, sFileSpec
.InvokeVerbEx "Print"
End With
End With
End Sub
Public Sub PrintFilesV2(ByRef vDir As Variant, ByRef sFileSpec As String)
Const SHCONTF_NONFOLDERS = &H40&
Dim objShell As Object
DoEvents
Set objShell = CreateObject("Shell.Application")
Set its = objShell.Namespace(vDir).Items
its.Filter SHCONTF_NONFOLDERS, sFileSpec
For i = 0 To its.Count - 1
its.Item(i).InvokeVerbEx ("Print")
Next
Set objShell = Nothing
End Sub |
Partager