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
| Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" _
(ByVal hWnd As Long, ByVal lpszOp As String, _
ByVal lpszFile As String, ByVal lpszParams As String, _
ByVal lpszDir As String, ByVal fsShowCmd As Long) As Long
'la macro d'impression, chems= chemin complet de la piece jointe
Sub printPDF(chems)
Dim Res As Long
Dim chemin_de_MaPj As String
chemin_de_MaPj = chems
Res = ShellExecute(0, "print", chemin_de_MaPj, "", "", 0)
End Sub
Sub PrintAllPDF()
Dim strFileName As String
Dim strPath As String
strPath = "c:\temp\"
strFileName = Dir(strPath + "*.pdf", vbNormal)
Do While strFileName <> ""
LeFichier = strPath + strFileName
printPDF (LeFichier)
strFileName = Dir
Loop
End Sub
Sub detache_PJ()
Dim MonOutlook As Outlook.Application
Dim Mail As Object
Dim LeMail As Outlook.MailItem
Dim LesMails As Object
Set MonOutlook = Outlook.Application
Set LesMails = MonOutlook.ActiveExplorer.Selection
For Each LeMail In LesMails
Dim pj As Attachment
For Each pj In LeMail.Attachments
If Right(UCase(pj.FileName), 4) = ".PDF" Then
LeFichier = "c:\temp\" & pj.FileName
pj.SaveAsFile (LeFichier)
End If
Next pj
Next LeMail
Set LesMails = Nothing
End Sub
Sub detache_et_imprime()
Shell "C:\temp\color_printer.bat", 0
Call detache_PJ
Call PrintAllPDF
MsgBox "Opération terminée, cliquez sur OK pour remettre l'imprimante par defaut"
Shell "C:\temp\kyofax_printer.bat", 0
Kill "C:\temp\*.pdf"
End Sub |
Partager