Bonjour à tous,
j'ai trouvé un fil interessant qui répond à ces deux questions
https://www.excel-downloads.com/threads/edition-pdf.112586/
Par contre, malgré le fait que j'ai installer PDFCreator,
je suis incapable de créer un PDF
J'aimerais dans un premier temps séparer le projet en 2 macros
soit l'une qui ne fait que créer un PDF
et l'autre, Créer un PDFet l'imprime
si quelqu'un aurait une piste de solution je serais preneur
merci
	
	
	
	
	
		
	
		
			
		
		
	
				
			j'ai trouvé un fil interessant qui répond à ces deux questions
https://www.excel-downloads.com/threads/edition-pdf.112586/
Par contre, malgré le fait que j'ai installer PDFCreator,
je suis incapable de créer un PDF
J'aimerais dans un premier temps séparer le projet en 2 macros
soit l'une qui ne fait que créer un PDF
et l'autre, Créer un PDFet l'imprime
si quelqu'un aurait une piste de solution je serais preneur
merci
		Code:
	
	
	Sub PrintTest()
    Call PrintSheetInPDF(Worksheets("Sheet1"))
End Sub '~PrintTest
Sub PrintSheetInPDF(shSheet As Worksheet)
    Dim pdfjob      As Object
    Dim sPDFName    As String
    Dim sPDFPath    As String
    
    '/// Changer le nom du fichier de sortie sur la ligne ci dessous: ///
    sPDFName = ThisWorkbook.Name & "_" & shSheet.Name & ".pdf"
    sPDFPath = ThisWorkbook.Path
    'Check if worksheet is empty and exit if so
    
    shSheet.Select
    
    If IsEmpty(shSheet.UsedRange) Then Exit Sub
    
    ' ##############################
    ' Pas trés propre, mais je n'ai pas réussi à récupérer l'instance de la classe
    ' PDFCreator.clsPDFCreator avec la fonction GetObject
    ' Remarque : si la tache "PDFCreator.exe" n'existe pas, la fonction KillTask("PDFCreator.exe") ne fait rien
    Call KillTask("PDFCreator.exe")
    ' ##############################
 
    Set pdfjob = CreateObject("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
    'Imprime le document en PDF
    ActiveSheet.PrintOut copies:=1, ActivePrinter:="PDFCreator"
    'Attend que le document soit entré dans la file d'impression
    Do Until pdfjob.cCountOfPrintjobs = 1
        DoEvents
    Loop
    pdfjob.cPrinterStop = False
    'Attend que l'impression du document soit terminée
    Do Until pdfjob.cCountOfPrintjobs = 0
        DoEvents
    Loop
    With pdfjob
        .cDefaultPrinter = DefaultPrinter
        .cClearCache
        Application.Wait (Now + TimeValue("0:00:3"))
        .cClose
    End With
    
    Set pdfjob = Nothing
End Sub '~PrintSheetInPDF
Sub KillTask(sAppName As String)
    Dim oProcList   As Object
    Dim oWMI        As Object
    Dim oProc       As Object
    
    'Create WMI object instance:
    Set oWMI = GetObject("winmgmts:")
    If IsNull(oWMI) = False Then
        'Create object collection of Win32 processes:
        Set oProcList = oWMI.InstancesOf("win32_process")
        'Iterate through the enumerated collection:
        For Each oProc In oProcList
            If UCase(oProc.Name) = UCase(sAppName) Then
                oProc.Terminate (0)
            End If
        Next oProc
    Else
        'Report Error
        MsgBox "Killing """ & sAppName & """ - Can't create WMI Object.", vbOKOnly + vbCritical, "CloseAPP_B"
    End If
    
    'Clear out the objects:
    Set oProcList = Nothing
    Set oWMI = Nothing
End Sub '~KillTask