Bonjour à tous,
J'ai adapté une macro trouvé sur le forum pour imprimer en PDF.
Elle fonctionne très bien mais je souhaiterai spécifer le chemin d'enregistrement sur mon ordinateur du fichier PDF créé
Merci d'avance pour vos lumières.
Sub imprPdf()
'
Dim pdfjob As Object, myprint As String, Port As Integer, fichname As String
Dim txt As String, NomPdf As String, DefaultPrinter As String
For Port = 0 To 9
myprint = "PDFCreator sur Ne0" & Port & ":"
On Error Resume Next
ActivePrinter = myprint
If ActivePrinter = myprint Then
Exit For
End If
Next
Set pdfjob = CreateObject("PDFCreator.clsPDFCreator")
With pdfjob
If .cStart("/NoProcessingAtStartup") = False Then
MsgBox " PDFCreator n'a pu tre dŽmarrer.", vbCritical + vbOKOnly, "PrtPDFCreator"
Exit Sub
End If
End With
NomPdf = ActiveSheet.Name & "_" & ActiveSheet.Range("M1") & ".pdf"
fichname = ThisWorkbook.Path & "\" & NomPdf
txt = Dir(fichname, vbNormal)
If txt <> "" Then
MsgBox "Ce fichier existe dŽja"
Exit Sub
End If
With pdfjob
.cOption("UseAutosave") = 1
.cOption("UseAutisaveDirectory") = 1
.cOption("AutosaveDirectory") = (ThisWorkbook.Path)
.cOption("AutosaveFilename") = NomPdf
.cOption("AutosaveFormat") = 0
.cClearCache
DefaultPrinter = .cDefaultprinter
End With
ActiveSheet.PrintOut Copies:=1, ActivePrinter:="PDFCreator"
Do Until pdfjob.cCountOfPrintjobs = 1
DoEvents
Loop
pdfjob.cPrinterStop = False
Do Until pdfjob.cCountOfPrintjobs = 0
DoEvents
Loop
With pdfjob
.cDefaultprinter = DefaultPrinter
.cClearCache
.cClose
End With
Set pdfjob = Nothing
MsgBox ("Le nom de votre fichier : " & NomPdf)
End Sub
J'ai adapté une macro trouvé sur le forum pour imprimer en PDF.
Elle fonctionne très bien mais je souhaiterai spécifer le chemin d'enregistrement sur mon ordinateur du fichier PDF créé
Merci d'avance pour vos lumières.
Sub imprPdf()
'
Dim pdfjob As Object, myprint As String, Port As Integer, fichname As String
Dim txt As String, NomPdf As String, DefaultPrinter As String
For Port = 0 To 9
myprint = "PDFCreator sur Ne0" & Port & ":"
On Error Resume Next
ActivePrinter = myprint
If ActivePrinter = myprint Then
Exit For
End If
Next
Set pdfjob = CreateObject("PDFCreator.clsPDFCreator")
With pdfjob
If .cStart("/NoProcessingAtStartup") = False Then
MsgBox " PDFCreator n'a pu tre dŽmarrer.", vbCritical + vbOKOnly, "PrtPDFCreator"
Exit Sub
End If
End With
NomPdf = ActiveSheet.Name & "_" & ActiveSheet.Range("M1") & ".pdf"
fichname = ThisWorkbook.Path & "\" & NomPdf
txt = Dir(fichname, vbNormal)
If txt <> "" Then
MsgBox "Ce fichier existe dŽja"
Exit Sub
End If
With pdfjob
.cOption("UseAutosave") = 1
.cOption("UseAutisaveDirectory") = 1
.cOption("AutosaveDirectory") = (ThisWorkbook.Path)
.cOption("AutosaveFilename") = NomPdf
.cOption("AutosaveFormat") = 0
.cClearCache
DefaultPrinter = .cDefaultprinter
End With
ActiveSheet.PrintOut Copies:=1, ActivePrinter:="PDFCreator"
Do Until pdfjob.cCountOfPrintjobs = 1
DoEvents
Loop
pdfjob.cPrinterStop = False
Do Until pdfjob.cCountOfPrintjobs = 0
DoEvents
Loop
With pdfjob
.cDefaultprinter = DefaultPrinter
.cClearCache
.cClose
End With
Set pdfjob = Nothing
MsgBox ("Le nom de votre fichier : " & NomPdf)
End Sub