Alt+F11 : Outils / Macro / Visual Basic Editor
Alt+O: Outils
R: Références...
<cliquer> pour sélectionner "PDFCreator"
Option Explicit
Private Declare Sub Sleep Lib "kernel32.dll" (ByVal dwMilliseconds As Long)
Public Sub ImprimePDF(PDFName As String, PDFLocation As String)
Dim PDFCreator1 As PDFCreator.clsPDFCreator ' Objet PDF
Dim DefaultPrinter As String ' Imprimante par Défaut (mémorisation)
Dim c As Long ' compteur Temporisation
Dim OutputFilename As String ' Nom du Fichier Généré
Set PDFCreator1 = New clsPDFCreator
With PDFCreator1
.cStart "/NoProcessingAtStartup"
.cOption("UseAutosave") = 1
.cOption("UseAutosaveDirectory") = 1
.cOption("AutosaveDirectory") = PDFLocation ' Répertoire de stockage du Fichier PDF généré
Debug.Print PDFName ' Remplace par des _ les caractères interdits
.cOption("AutosaveFilename") = _
PDFName & "-" & ActiveSheet.Name ' Nom de Fichier = <nom du Fichier>-<nom de l'Onglet>
.cOption("AutosaveFormat") = 0 ' 0 = PDF
DefaultPrinter = .cDefaultPrinter ' Mémorise l'Imprimante pas défaut
.cDefaultPrinter = "PDFCreator" ' écrase par PDFCreator
.cClearCache
End With
ActiveSheet.PrintOut Copies:=1, ActivePrinter:="PDFCreator"
Do Until PDFCreator1.cCountOfPrintjobs = 1 ' Attend la Fin du travail pour quitter
DoEvents
Sleep 1000
Loop
Sleep 1000
PDFCreator1.cPrinterStop = False
c = 0 ' Attend la Fin d'Ecriture
Do While (PDFCreator1.cOutputFilename = "") And (c < 50) ' au besoin 50x200ms (1 sec)
c = c + 1
Sleep 200
Loop
OutputFilename = PDFCreator1.cOutputFilename ' Récupère le nom du Fichier Généré
With PDFCreator1
.cDefaultPrinter = DefaultPrinter ' Réattribue l'Imprimante initiale
Sleep 200 ' Tempo de prise en compte avant fermeture
.cClose
End With
Sleep 2000 ' Tempo 2 sec permettant d'assurer la libération de PDFCreator de la Mémoire
If OutputFilename = "" Then
MsgBox "Création Fichier pdf." & vbCrLf & vbCrLf & _
"Une Erreur s'est produite: Délai dépassé!", vbExclamation + vbSystemModal
End If
End Sub
Option Explicit
Private Declare Sub Sleep Lib "kernel32.dll" (ByVal dwMilliseconds As Long)
Public Sub ImprimeTousPDF(PDFName As String, PDFLocation As String)
Dim PDFCreator1 As PDFCreator.clsPDFCreator
Dim DefaultPrinter As String ' Imprimante par Défaut (mémorisation)
Dim c As Long ' compteur Temporisation
Dim OutputFilename As String ' Nom du Fichier Généré
Dim i As Integer ' compteur d'onglets
Set PDFCreator1 = New clsPDFCreator
With PDFCreator1
.cStart "/NoProcessingAtStartup"
.cOption("UseAutosave") = 1
.cOption("UseAutosaveDirectory") = 1
.cOption("AutosaveDirectory") = PDFLocation ' Répertoire de stockage du Fichier PDF généré
Debug.Print PDFName ' Remplace par des _ les caractères interdits
.cOption("AutosaveFilename") = PDFName ' Nom de Fichier = <nom du Fichier>
.cOption("AutosaveFormat") = 0 ' 0 = PDF
DefaultPrinter = .cDefaultPrinter ' Mémorise l'Imprimante pas défaut
.cDefaultPrinter = "PDFCreator" ' écrase par PDFCreator
.cClearCache
End With
For i = 1 To Application.Sheets.Count
Application.Sheets(i).PrintOut Copies:=1, ActivePrinter:="PDFCreator"
Next i
Do Until PDFCreator1.cCountOfPrintjobs = Application.Sheets.Count ' Attend la Fin du travail pour quitter
DoEvents
Sleep 1000
Loop
Sleep 1000
PDFCreator1.cCombineAll
Sleep 1000
PDFCreator1.cPrinterStop = False
c = 0 ' Attend la Fin d'Ecriture
Do While (PDFCreator1.cOutputFilename = "") And (c < 50) ' au besoin 50x200ms (1 sec)
c = c + 1
Sleep 200
Loop
OutputFilename = PDFCreator1.cOutputFilename ' Récupère le nom du Fichier Généré
With PDFCreator1
.cDefaultPrinter = DefaultPrinter ' Réattribue l'Imprimante initiale
Sleep 200 ' Tempo de prise en compte avant fermeture
.cClose
End With
Sleep 2000 ' Tempo 2 sec permettant d'assurer la libération de PDFCreator de la Mémoire
If OutputFilename = "" Then
MsgBox "Création Fichier pdf." & vbCrLf & vbCrLf & _
"Une Erreur s'est produite: Délai dépassé!", vbExclamation + vbSystemModal
End If
End Sub
Public Sub Petit_Test() ' Met des données dans les 3 principaux onglets
Sheets(1).Range("A1").Value = "Petit Test - Ceci est la page 1"
Sheets(2).Range("A1").Value = "Petit Test - Ceci est la page 2"
Sheets(3).Range("A1").Value = "Petit Test - Ceci est la page 3"
' Imprime la page de l'onglet principal
Call ImprimePDF("Mon_PDF", "C:\")
' Imprime la page de tous les onglets dans un seul document
Call ImprimeTousPDF("Mon_PDF", "C:\")
MsgBox "Petit Test Terminé" & vbCrLf & vbCrLf & _
"Fichiers PDF générés dans C:\", vbExclamation + vbSystemModal
Alt+F11 : Outils / Macro / Visual Basic Editor
Alt+O: Outils
R: References...
<click> to select "PDFCreator"
Option Explicit
Private Declare Sub Sleep Lib "kernel32.dll" (ByVal dwMilliseconds As Long)
Public Sub ImprimePDF(PDFName As String, PDFLocation As String)
Dim PDFCreator1 As PDFCreator.clsPDFCreator ' Objet PDF
Dim DefaultPrinter As String ' Imprimante par Défaut (mémorisation)
Dim c As Long ' compteur Temporisation
Dim OutputFilename As String ' Nom du Fichier Généré
Set PDFCreator1 = New clsPDFCreator
With PDFCreator1
.cStart "/NoProcessingAtStartup"
.cOption("UseAutosave") = 1
.cOption("UseAutosaveDirectory") = 1
.cOption("AutosaveDirectory") = PDFLocation ' Répertoire de stockage du Fichier PDF généré
Debug.Print PDFName ' Remplace par des _ les caractères interdits
.cOption("AutosaveFilename") = _
PDFName & "-" & ActiveSheet.Name ' Nom de Fichier = <nom du Fichier>-<nom de l'Onglet>
.cOption("AutosaveFormat") = 0 ' 0 = PDF
DefaultPrinter = .cDefaultPrinter ' Mémorise l'Imprimante par défaut
.cDefaultPrinter = "PDFCreator" ' écrase par PDFCreator
.cClearCache
End With
ActiveSheet.PrintOut Copies:=1, ActivePrinter:="PDFCreator"
Do Until PDFCreator1.cCountOfPrintjobs = 1 ' Attend la Fin du travail pour quitter
DoEvents
Sleep 1000
Loop
Sleep 1000
PDFCreator1.cPrinterStop = False
c = 0 ' Attend la Fin d'Ecriture
Do While (PDFCreator1.cOutputFilename = "") And (c < 50) ' au besoin 50x200ms (1 sec)
c = c + 1
Sleep 200
Loop
OutputFilename = PDFCreator1.cOutputFilename ' Récupère le nom du Fichier Généré
With PDFCreator1
.cDefaultPrinter = DefaultPrinter ' Réattribue l'Imprimante initiale
Sleep 200 ' Tempo de prise en compte avant fermeture
.cClose
End With
Sleep 2000 ' Tempo 2 sec permettant d'assurer la libération de PDFCreator de la Mémoire
If OutputFilename = "" Then
MsgBox "Création Fichier pdf." & vbCrLf & vbCrLf & _
"Une Erreur s'est produite: Délai dépassé!", vbExclamation + vbSystemModal
End If
End Sub
Option Explicit
Private Declare Sub Sleep Lib "kernel32.dll" (ByVal dwMilliseconds As Long)
Public Sub ImprimeTousPDF(PDFName As String, PDFLocation As String)
Dim PDFCreator1 As PDFCreator.clsPDFCreator
Dim DefaultPrinter As String ' Imprimante par Défaut (mémorisation)
Dim c As Long ' compteur Temporisation
Dim OutputFilename As String ' Nom du Fichier Généré
Dim i As Integer ' compteur d'onglets
Set PDFCreator1 = New clsPDFCreator
With PDFCreator1
.cStart "/NoProcessingAtStartup"
.cOption("UseAutosave") = 1
.cOption("UseAutosaveDirectory") = 1
.cOption("AutosaveDirectory") = PDFLocation ' Répertoire de stockage du Fichier PDF généré
Debug.Print PDFName ' Remplace par des _ les caractères interdits
.cOption("AutosaveFilename") = PDFName ' Nom de Fichier = <nom du Fichier>
.cOption("AutosaveFormat") = 0 ' 0 = PDF
DefaultPrinter = .cDefaultPrinter ' Mémorise l'Imprimante par défaut
.cDefaultPrinter = "PDFCreator" ' écrase par PDFCreator
.cClearCache
End With
For i = 1 To Application.Sheets.Count
Application.Sheets(i).PrintOut Copies:=1, ActivePrinter:="PDFCreator"
Next i
Do Until PDFCreator1.cCountOfPrintjobs = Application.Sheets.Count ' Attend la Fin du travail pour quitter
DoEvents
Sleep 1000
Loop
Sleep 1000
PDFCreator1.cCombineAll
Sleep 1000
PDFCreator1.cPrinterStop = False
c = 0 ' Attend la Fin d'Ecriture
Do While (PDFCreator1.cOutputFilename = "") And (c < 50) ' au besoin 50x200ms (1 sec)
c = c + 1
Sleep 200
Loop
OutputFilename = PDFCreator1.cOutputFilename ' Récupère le nom du Fichier Généré
With PDFCreator1
.cDefaultPrinter = DefaultPrinter ' Réattribue l'Imprimante initiale
Sleep 200 ' Tempo de prise en compte avant fermeture
.cClose
End With
Sleep 2000 ' Tempo 2 sec permettant d'assurer la libération de PDFCreator de la Mémoire
If OutputFilename = "" Then
MsgBox "Création Fichier pdf." & vbCrLf & vbCrLf & _
"Une Erreur s'est produite: Délai dépassé!", vbExclamation + vbSystemModal
End If
End Sub
Public Sub Petit_Test() ' Met des données dans les 3 principaux onglets
Sheets(1).Range("A1").Value = "Petit Test - Ceci est la page 1"
Sheets(2).Range("A1").Value = "Petit Test - Ceci est la page 2"
Sheets(3).Range("A1").Value = "Petit Test - Ceci est la page 3"
' Imprime la page de l'onglet principal
Call ImprimePDF("Mon_PDF", "C:\")
' Imprime la page de tous les onglets dans un seul document
Call ImprimeTousPDF("Mon_PDF", "C:\")
MsgBox "Petit Test Terminé" & vbCrLf & vbCrLf & _
"Fichiers PDF générés dans C:\", vbExclamation + vbSystemModal
Utilisateurs parcourant ce forum: Aucun utilisateur enregistré et 1 invité