Salut,
Je sais pas comment tu t'es débrouillé pour ta recherche mais en 2 secondes j'ai trouvé cela :
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
| Option Explicit
Sub PrintToPDF_MultiSheet_Early()
Dim pdfjob As PDFCreator.clsPDFCreator
Dim sPDFName As String
Dim sPDFPath As String
Dim lSheet As Long
Set pdfjob = New PDFCreator.clsPDFCreator
sPDFPath = ActiveWorkbook.Path & Application.PathSeparator
If pdfjob.cStart("/NoProcessingAtStartup") = False Then
MsgBox "Can't initialize PDFCreator.", vbCritical + _
vbOKOnly, "PrtPDFCreator"
Exit Sub
End If
For lSheet = 1 To ActiveWorkbook.Sheets.Count
'Check if worksheet is empty and skip if so
If Not IsEmpty(ActiveSheet.UsedRange) Then
With pdfjob
'/// Change the output file name here! ///
sPDFName = "testPDF" & Sheets(lSheet).Name & ".pdf"
.cOption("UseAutosave") = 1
.cOption("UseAutosaveDirectory") = 1
.cOption("AutosaveDirectory") = sPDFPath
.cOption("AutosaveFilename") = sPDFName
.cOption("AutosaveFormat") = 0 ' 0 = PDF
.cClearCache
End With
'Print the document to PDF
Worksheets(lSheet).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
End If
Next lSheet
pdfjob.cClose
Set pdfjob = Nothing
End Sub |
Ce n'est pas de moi je préviens. En tout cas, cela fait exactement ce que tu souhaites de A à Z : tu as x feuilles. Les x feuilles sont sauvegardées comme différents PDF. Tu n'as plus qu'à adapter "légèrement".
Allez, j'te donne un indice : il va falloir changer
sPDFName = "testPDF" & Sheets(lSheet).Name & ".pdf"
si tu ne veux pas que le nom de ton fichier ait cette tête là et
cOption("AutosaveDirectory") = sPDFPath
pour le path. Bien sûr pense à changer tout ce qui a rapport avec cela.
Bonne chance pour la suite, il ne te reste vraiment plus que 5 minutes de boulot là !
Partager