1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47
| Option Explicit
'Ouvrir fichiers dans leur programme par défaut
'Private Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" _
'(ByVal hwnd As Long, ByVal lpOperation As String, ByVal lpFile As String, _
'ByVal lpParameters As String, ByVal lpDirectory As String, ByVal nShowCmd As Long) As Long
Public chemsave As String
Public feuil As String
Sub ToPdf()
Dim pdfjob As Object
Dim DefaultPrinter
chemsave = ThisWorkbook.Sheets("MATRICE").Range("A111").Value 'tu peux changer la feuille et la cellule
'If chemsave = "" Then Exit Sub
Set pdfjob = CreateObject("PDFCreator.clsPDFCreator")
'NomExcel = ThisWorkbook.Name
'NomPdf = Left(NomExcel, Len(NomExcel) - 4) & ".pdf"
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") = chemsave 'chemin destination
.cOption("AutosaveFilename") = feuil & ".pdf" 'nom de la feuille
.cOption("AutosaveFormat") = 0
.cClearCache
End With
ActiveWindow.SelectedSheets.PrintOut From:=1, To:=32766, Copies:=1, ActivePrinter:="PDFCreator" 'on imprime la feuille active
'ThisWorkbook.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
'Dim Ret As Variant
'Ret = ShellExecute(hwnd, "open", chemsave & To_PDF.ComboBox1.Value & ".pdf", "", vbNullString, 1) 'ouverture du pdf
MsgBox "Votre PDF se trouve à cet emplacement: " & chemsave, vbInformation, "Convertir en PDF"
End Sub |
Partager