Créer automatiquement des fichiers PDF.

PAULOM

XLDnaute Nouveau
Bonjour,

J'aimerai qu'Excel me créé des fichiers pdf (via PDFCreator) automatiquement dans une macro.

Voici le code:

Code:
Option Explicit
 
Sub Tst_PdfCreator()
Dim JobPDF As Object
Dim sNomPDF As String
Dim sCheminPDF As String
 
    sNomPDF = "Essai_PdfCreator.pdf"
    sCheminPDF = ActiveWorkbook.Path & Application.PathSeparator
 
    If IsEmpty(ActiveSheet.UsedRange) Then Exit Sub
 
    Set JobPDF = CreateObject("PDFCreator.clsPDFCreator")
 
    With JobPDF
        If .cStart("/NoProcessingAtStartup") = False Then
            MsgBox "Initialisation de PDFCreator impossible", vbCritical + vbOKOnly, "PDFCreator"
            Exit Sub
        End If
        .cOption("UseAutosave") = 1
        .cOption("UseAutosaveDirectory") = 1
        .cOption("AutosaveDirectory") = sCheminPDF
        .cOption("AutosaveFilename") = sNomPDF
 
        '   0=PDF, 1=Png, 2=jpg, 3=bmp, 4=pcx, 5=tif, 6=ps, 7=eps, 8=txt
        .cOption("AutosaveFormat") = 0
 
        .cClearCache
    End With
 
    ActiveWorkbook.PrintOut copies:=1, ActivePrinter:="PDFCreator"
 
    'Fichier dans la file d'attente
    Do Until JobPDF.cCountOfPrintjobs = 1
        DoEvents
    Loop
    JobPDF.cPrinterStop = False
 
    'Attendre que la file d'attente soit vide
    Do Until JobPDF.cCountOfPrintjobs = 0
        DoEvents
    Loop
    JobPDF.cClose
    Set JobPDF = Nothing
  
End Sub

Le code marche parfaitement sauf que le problème est que 31 feuilles dans le classeur or il me créé le pdf seulement sur 22 feuilles or je voudrais la totalité des feuilles présentes dans mon classeur, ou alors créer 2 fichiers pdf distincts.

Un grand merci à vous.
 
Dernière édition:

MJ13

XLDnaute Barbatruc
Re : Créer automatiquement des fichiers PDF.

Bonjour Paulom

Voici un code que j'utilise pour imprimer un fichier en pdf avec PDFCreator:

Code:
Sub lance_PDF_Creator2()
'MJ pour [URL]https://www.excel-downloads.com/threads/creer-automatiquement-des-fichiers-pdf.123335/[/URL]
rn2 = Cells(ActiveCell.Rows.Row, 1) & "\" & ActiveCell.Value
 Workbooks.Open Filename:=rn2
Sheets.Select
ActiveWorkbook.Save
ActiveWorkbook.Close
RN = "C:\Program Files\PDFCreator\pdfcreator.exe /PF" & "" & Chr(34) & rn2 & Chr(34) & ""
Shell (RN), vbMaximizedFocus
End Sub

Il faut avoir le nom du fichier que tu sélectionnes en colonne 2 et sur la même ligne en colonne 1, tu dois avoir le chemin du fichier.
 

PAULOM

XLDnaute Nouveau
Re : Créer automatiquement des fichiers PDF.

Bonjour Paulom

Voici un code que j'utilise pour imprimer un fichier en pdf avec PDFCreator:

Code:
Sub lance_PDF_Creator2()
'MJ pour [URL]https://www.excel-downloads.com/threads/creer-automatiquement-des-fichiers-pdf.123335/[/URL]
rn2 = Cells(ActiveCell.Rows.Row, 1) & "\" & ActiveCell.Value
 Workbooks.Open Filename:=rn2
Sheets.Select
ActiveWorkbook.Save
ActiveWorkbook.Close
RN = "C:\Program Files\PDFCreator\pdfcreator.exe /PF" & "" & Chr(34) & rn2 & Chr(34) & ""
Shell (RN), vbMaximizedFocus
End Sub

Il faut avoir le nom du fichier que tu sélectionnes en colonne 2 et sur la même ligne en colonne 1, tu dois avoir le chemin du fichier.


Merci mais t'a macro ne fonctionne pas.
Il me créé même pas le pdf....
 

Discussions similaires

Statistiques des forums

Discussions
312 571
Messages
2 089 809
Membres
104 278
dernier inscrit
LENZY