• Initiateur de la discussion Initiateur de la discussion vincent50
  • Date de début Date de début

Boostez vos compétences Excel avec notre communauté !

Rejoignez Excel Downloads, le rendez-vous des passionnés où l'entraide fait la force. Apprenez, échangez, progressez – et tout ça gratuitement ! 👉 Inscrivez-vous maintenant !

vincent50

XLDnaute Occasionnel
bonjour, j'ai trouvé ca sur un site mais ca bug, pouvez vous m'aider
Sub testPrintPDF()
Dim oldPrinter As String
Dim stChemin As String
Dim stNom As String
' Affichage de la fenêtre de PDF
Shell "C:\Program Files\PDFCreator\PDFCreator.exe", vbNormalFocus

Dim PDFCreator1 As New clsPDFCreator (c'est la que ca bug)
oldPrinter = ActivePrinter
'On va mettre en mémoire dans une
'variable le nom de l'imprimante par défaut
ActivePrinter = "PDFCreator"
'Mettre comme imprimante par défaut PDFCreator
If Len(ActiveDocument.Path) = 0 Then
stChemin = "c:\temp"
Else
stChemin = ActiveDocument.Path
End If
'Si le document n'a pas été sauvegardé, le PDF sera dans le répertoire c:\temp
'et un nom par défaut documentPDF;pdf
If Len(ActiveDocument.Name) = 0 Then
stNom = "documentPDF.pdf"
Else
stNom = ActiveDocument.Name
End If
'les option PDFCreator
With PDFCreator1
.cOption("UseAutosave") = 1
.cOption("UseAutosaveDirectory") = 1
.cOption("AutosaveDirectory") = stChemin
.cOption("AutosaveFilename") = stNom
.cOption("AutosaveFormat") = 0 ' 0 = PDF
.cStart
.cClearCache
End With
ActiveDocument.PrintOut Background:=True
PDFCreator1.cClose
ActivePrinter = oldPrinter
' Change l'imprimante par défaut

End Sub
 
Re : macro qui bug

Bonjour Vincent50 🙂,
Quel est le message d'erreur ?
Est-ce que le chemin "C:\Program Files\PDFCreator\PDFCreator.exe" correspond bien à l'emplacement de PDFCreator sur ton disque ?
N'y a-t-il pas une référence à PDFCreator à ouvrir ?
Bon courage 😎
 
Re : macro qui bug

Re 🙂,
C'est donc clsPDFCreator qui n'est pas reconnu comme type d'objet, donc la référence à PDFCreator ne doit pas être ouverte. Pour cela, dans la fenêtre Visual Basic, menu Outils -> Références... une fenêtre s'affiche. Dans la liste tu cherches une Library qui concerne PDFCreator et tu la coche. Cela donnera accès à VBA aux instructions objet pour manipuler via le code.
Pour le chemin, il faut vérifier que PDFCreator.exe est installé dans "C:\Program Files\PDFCreator\PDFCreator.exe", donc dans ton disque C, dans le dossier Program Files, sous dossier PDFCreator.
Bonne journée 😎
 
Re : macro qui bug

J'ai trouvé autre chose sur le forum qui fonctionne tres bien sauf qu'a la fin pdfcreator reste en imprimante par default et moi j'aimerai recuperer mon imprimante papier par default.
voila le code:

Sub testPrintPDF()
Dim oldPrinter As String
oldPrinter = ActivePrinter
newprinter = "PDFCreator"
newprinter = ActivePrinter
Dim pdfjob As PDFCreator.clsPDFCreator
Dim sPDFName As String
Dim sPDFPath As String
'/// Change the output file name here! ///
sPDFName = "testPDF.pdf"
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("AutosaveFilename") = sPDFName
.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
pdfjob.cClose
oldPrinter = ActivePrinter

End Sub

merci de votre aide
je sais que je me repete, mais j'apprecie beaucoup
 
- Navigue sans publicité
- Accède à Cléa, notre assistante IA experte Excel... et pas que...
- Profite de fonctionnalités exclusives
Ton soutien permet à Excel Downloads de rester 100% gratuit et de continuer à rassembler les passionnés d'Excel.
Je deviens Supporter XLD

Discussions similaires

Réponses
4
Affichages
596
Réponses
3
Affichages
924
Réponses
2
Affichages
1 K
Retour