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
| Dim pdfjob
Dim NomExcel, NomPdf, DefaultPrinter
Set pdfjob = CreateObject("PDFCreator.clsPDFCreator")
Dim Chemin As String, Fich As String, rep
Chemin = "c:\temp"
Fich = CreateObject("Scripting.FileSystemObject").GetBaseName(ActiveWorkbook.Name) & ".pdf"
rep = Dir(Chemin & "\" & Fich)
If rep = "" Then
MsgBox "le fichier n'existe pas création du fichier PDFCreator"
Impression:
With pdfjob
If .cStart("/NoProcessingAtStartup") = False Then
MsgBox "Impossible d'initialiser PDFCreator.", vbCritical + vbOKOnly, "PrtPDFCreator"
'GoTo Error
Exit Sub
End If
.cOption("UseAutosave") = 1
.cOption("UseAutisaveDirectory") = 1
.cOption("AutosaveDirectory") = Chemin ' chemin enregistrement du classeur actuel
.cOption("AutosaveFilename") = Fich
.cOption("AutosaveFormat") = 0
.cClearCache
End With
'ThisWorkbook.PrintOut Copies:=1, ActivePrinter:="PDFCreator" 'imprime le classeur entier
ThisWorkbook.Sheets("Feuil1").PrintOut Copies:=1, ActivePrinter:="PDFCreator" 'imprime l'onglet pour mise en page définir la partie à imprimer
'Selection.PrintOut Copies:=1, ActivePrinter:="PDFCreator" 'imprime la selection
Do Until pdfjob.cCountOfPrintjobs = 1
DoEvents
Loop
pdfjob.cPrinterStop = False
Do Until pdfjob.cCountOfPrintjobs = 0
DoEvents
Loop
With pdfjob
.cDefaultPrinter = DefaultPrinter
.cClearCache
.cClose
End With
Else
réponse = MsgBox("le fichier existe voulez-vous le remplacer ?", vbYesNo)
If réponse = vbYes Then
MsgBox "Remplacement du fichier existant"
GoTo Impression
Else
MsgBox "Sortie de la procédure"
End If
End If |
Partager