Re : Enregistrer sous pdf
Bonjour,
Ci dessous le code pour enregistrer en pdf sans passer par la boite de dialogue de pdf creator. (Vers 0.9.6)
Comment dans le code, je peux indiquer la feuille concerné (feuil1, ou feuil2)?
Je vous en remercie par avance
Manu
Sub PrintToPDF_Early2()
'Author : Ken Puls (Excelguru.ca | Tips and pointers for Excel and other MS Office applications)
'Macro Purpose: Print to PDF file using PDFCreator
' (Download from SourceForge.net: PDFCreator)
' Designed for early bind, set reference to PDFCreator
Dim pdfjob As PDFCreator.clsPDFCreator
Dim sPDFName As String
Dim sPDFPath As String
Dim RetVal As Variant
'/// Change the output file name here! ///
sPDFName = "J9"
sPDFPath = ActiveWorkbook.Path & Application.PathSeparator
'Check if worksheet is empty and exit if so
If IsEmpty(ActiveSheet.UsedRange) Then Exit Sub
Set pdfjob = New PDFCreator.clsPDFCreator
With pdfjob
If .cStart("/NoProcessingAtStartup") = False Then
MsgBox "Can't initialize PDFCreator.", vbCritical + _
vbOKOnly, "PrtPDFCreator"
Exit Sub
End If
.cOption("UseAutosave") = 1
.cOption("UseAutosaveDirectory") = 1
'.cOption("AutosaveDirectory") = sPDFPath
.cOption("AutosaveDirectory") = Range("J10")
.cOption("AutosaveFilename") = Range("J9")
.cOption("AutosaveFormat") = 0 ' 0 = PDF
.cClearCache
End With
'Print the document to PDF
ActiveSheet.PrintOut copies:=1, ActivePrinter:="PDFCreator"
'Wait until the print job has entered the print queue
Do Until pdfjob.cCountOfPrintjobs = 1
DoEvents
Loop
pdfjob.cPrinterStop = False
'Wait until PDF creator is finished then release the objects
Do Until pdfjob.cCountOfPrintjobs = 0
DoEvents
Loop
RetVal = Shell("Taskkill /IM PDFCreator.exe /F", 0)
' pdfjob.cClose
'Set pdfjob = Nothing
End Sub