Impression avec PDF creator

Fermé
Thevaenthi Messages postés 1 Date d'inscription mardi 27 septembre 2016 Statut Membre Dernière intervention 27 septembre 2016 - 27 sept. 2016 à 08:49
tyranausor Messages postés 3545 Date d'inscription jeudi 6 août 2009 Statut Membre Dernière intervention 1 avril 2022 - 8 nov. 2016 à 00:04
Bonjour à tous,
Je débute dans VBA et j'essaie d'imprimer des étiquettes de produits en utilisant l'option pdf creator de Excel.
Pour cela j'ai un tableau avec mes données et un premier code VBA me permet de mettre en forme mon étiquette de produit à partir des données du tableau. Ce code fonctionne, par contre là où je bloque c'est pour l'impression. Je souhaite obtenir un seul fichier Pdf pour l'ensemble des étiquettes de produit en utilisant la fonction "Wait-Collect".
Dans mon cas, Pdf creator m'imprime la première étiquette et pour les étiquettes suivantes j'ai un message d'erreur "Can't initialize PDF Creator". J'ai essayé de parcourir plusieurs forum mais je ne trouve pas la solution à mon problème.

Voici mes codes : (le premier pour la mise en forme de l'étiquette et la deuxième pour l'impression PDF)
Sub impression()

Range("V21").Activate
ligne = ActiveCell.Row
colonne = ActiveCell.Column

Do

Range("A7") = Cells(ligne, colonne).Value
Range("D7") = Cells(ligne, colonne).Offset(0, 1).Value
Range("I7") = Cells(ligne, colonne).Offset(0, 7).Value
Range("I5") = Cells(ligne, colonne).Offset(0, 8).Value
Range("M5") = Cells(ligne, colonne).Offset(0, 9).Value
Range("L1") = Cells(ligne, colonne).Offset(0, 10).Value
Range("Q1") = Cells(ligne, colonne).Offset(0, 11).Value
Range("A14") = Cells(ligne, colonne).Offset(0, 12).Value

code = Range("A7") & "/" & Range("I5") & "/" & Range("M5") & "/" & Range("I7")
Range("V17").Value = code

'Range("A16") = code

i = 1
j = 16
IMPRES: Range("A" & i & ":Q" & j).Select
Selection.Borders(xlDiagonalDown).LineStyle = xlNone
Selection.Borders(xlDiagonalUp).LineStyle = xlNone
With Selection.Borders(xlEdgeLeft)
.LineStyle = xlContinuous
.ColorIndex = 0
.TintAndShade = 0
.Weight = xlMedium
End With
With Selection.Borders(xlEdgeTop)
.LineStyle = xlContinuous
.ColorIndex = 0
.TintAndShade = 0
.Weight = xlMedium
End With
With Selection.Borders(xlEdgeBottom)
.LineStyle = xlContinuous
.ColorIndex = 0
.TintAndShade = 0
.Weight = xlMedium
End With
With Selection.Borders(xlEdgeRight)
.LineStyle = xlContinuous
.ColorIndex = 0
.TintAndShade = 0
.Weight = xlMedium
End With

ActiveSheet.PageSetup.PrintArea = "A" & i & ":Q" & j
With ActiveSheet.PageSetup
.CenterHorizontally = True
.CenterVertically = True
.Orientation = xlPortrait
.BlackAndWhite = False
.Zoom = False
.FitToPagesWide = 1
.FitToPagesTall = 1
End With

Call Module2.PrintToPDF
'ligne = ActiveCell.Row
'Debut = ligne

ligne = ligne + 1

Cells(ligne, colonne).Activate
Loop Until IsEmpty(ActiveCell)

Range("V17") = ""

End Sub



Sub PrintToPDF()
Dim pdfjob As PDFCreator.clsPDFCreator
Dim sPDFName As String
Dim sPDFPath As String
'Définition du nom de fichier à exporter
sPDFName = "Fichier PDF du " & Range("A7").Value & ".pdf"
'Chemin du dossier pour l'enregistrement
sPDFPath = ActiveWorkbook.Path & Application.PathSeparator
'Vérifier si la feuille est vide ou non
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("AutosaveFilename") = sPDFName
.cOption("AutosaveFormat") = 0 ' 0 = PDF
.cCombineAll
.cClearCache
End With
'Imprime le document en PDF
ActiveSheet.PrintOut copies:=1, ActivePrinter:="PDFCreator"
'Attendre jusqu'à ce que l'impression soit dans la file d'attente
Do Until pdfjob.cCountOfPrintjobs = 1
DoEvents
Loop
pdfjob.cPrinterStop = False
'Attendre que PDF Creator libère les objets
Do Until pdfjob.cCountOfPrintjobs = 1
DoEvents
Loop
pdfjob.cClose
Set pdfjob = Nothing
End Sub


Merci d'avance pour votre aide


A voir également:

1 réponse

tyranausor Messages postés 3545 Date d'inscription jeudi 6 août 2009 Statut Membre Dernière intervention 1 avril 2022 2 031
8 nov. 2016 à 00:04
Bonjour, dans ton post tu peux utiliser les balises
 (et recommandé) et surtout d'indenter ton code VBA, ce sera plus facile à lire

0