Re : macro excel impression PDF
Rebonjour,
J'ai découvert aprés quelques manipulations un nouveau petit problème.
La macro pour PDF fonctionne mais lorsque je fait une impression directe sur l'imprimante par défaut elle passe sur le spool PDFcreatore
Que dois je modifier pour le retour sur l'imprimante par défaut.
Ci-joint les deux macros.
Function ExistenceFichier(sFichier As String) As Boolean
ExistenceFichier = Dir(sFichier) <> ""
End Function
Sub ImprPdf()
Dim Rep As Long
Dim pdfjob As Object
Dim myprint As String
Dim Port As Integer
Dim fichname As String
Dim NomPdf As String
Dim 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.Range("M1") & ".pdf"
fichname = ThisWorkbook.Path & "\" & NomPdf
If ExistenceFichier(fichname) Then
Rep = MsgBox("Le fichier existe déjà" & vbCrLf & "L'écraser ?", vbYesNo)
End If
If Rep = 7 Then Exit Sub
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
Sub Impression()
'
' Impression de la feuille
'
ExecuteExcel4Macro "PRINT(1,,,1,,,,,,,,2,,,TRUE,,FALSE)"
End Sub