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
| Option Explicit
Private Declare Sub Sleep Lib "kernel32.dll" (ByVal dwMilliseconds As Long)
' Add a reference to PDFCreator
Private WithEvents PDFCreator1 As PDFCreator.clsPDFCreator
Function imprimeFeuille(ByVal f As String) As Boolean
Dim sauveprinter, nomPrinter As String
Dim fs
Dim i As Integer
Set PDFCreator1 = New clsPDFCreator
If PDFCreator1.cProgramIsRunning() Then
''Si PDFCreator est deja en cours, on recupere l'instance en cours
If PDFCreator1.cStart("/NoProcessingAtStartup", True) = False Then
imprimeFeuille = False
Exit Function
End If
''Sinon on en demarre une
ElseIf PDFCreator1.cStart("/NoProcessingAtStartup") = False Then
imprimeFeuille = False
Exit Function
End If
With PDFCreator1
.cPrinterStop = True
''On vide les autres impressions en attente
Do While .cCountOfPrintjobs() <> 0
.cDeletePrintjob (1)
Loop
.cReadOptionsFromFile (ThisWorkbook.Path + "\pdf.ini")
.cOption("UseAutosave") = 1
.cOption("UseAutosaveDirectory") = 1
.cOption("AutosaveFilename") = nomFichier
.cOption("AutosaveDirectory") = nomRep
.cOption("AutosaveFormat") = 0 ''0 = PDF
.cClearCache
End With
sauveprinter = Application.ActivePrinter
For i = 0 To 9
nomPrinter = "PDFCreator sur Ne0" & i & ":"
On Error Resume Next
Application.ActivePrinter = "PDFCreator sur Ne0" & i & ":"
If ActivePrinter = nomPrinter Then Exit For
Next
Worksheets(f).Visible = True
Worksheets(f).PrintOut Copies:=1
Worksheets(f).Visible = False
Do Until PDFCreator1.cCountOfPrintjobs = 1
DoEvents
Sleep 300
Loop
Sleep 300
PDFCreator1.cPrinterStop = False
i = 0
Do Until PDFCreator1.cPrinterStop = True Or i > 10
DoEvents
Sleep 300
i = i + 1
Loop
PDFCreator1.cCloseRunningSession
Application.ActivePrinter = sauveprinter
imprimeFeuille = Dir(nomRep + nomFichier) <> ""
End Function
Private Sub PDFCreator1_eError()
MsgBox ("ERROR [" & PDFCreator1.cErrorDetail("Number") & "]: " & PDFCreator1.cErrorDetail("Description"))
End Sub
Private Sub PDFCreator1_eReady()
PDFCreator1.cPrinterStop = True
End Sub |
Partager