Macro Enregistrement PDF

Vince

XLDnaute Nouveau
Bonjour et bonne année le forum.

Je recherche une macro sous Excel 2007 et Adobe Acrobat 9 pour l'impression(enregistrement) au format pdf (adobe acrobat) de la zone d'impression avec la création auto du nom de fichier en faisant référence à plusieurs cellule (valeurs) dans un chemin détermine.

Exemple du nom de fichier pdf:

C:\Facture 2009\Nº de facture (C18)+Date (F18)+Nom Client (E9).pdf

Merci pour votre aide.
 

Pièces jointes

  • Classeur1.xls
    44 KB · Affichages: 174
  • Classeur1.xls
    44 KB · Affichages: 187
  • Classeur1.xls
    44 KB · Affichages: 185

kiki29

XLDnaute Barbatruc
Re : Macro Enregistrement PDF

Salut, sous Excel 2007, moyennant le téléchargement d'un complément qui rend possible
l'enregistrement en Pdf ou Xps


Utiliser le macro recorder et adapter le code généré
qui devrait ressembler à qqch comme :
Code:
Dim sDate As String, sNum As String
Dim sNom As String, sNomFichierPDF As String
    sNum = ActiveSheet.Range("C18")
    sDate = ActiveSheet.Range("F18")
    sNom = ActiveSheet.Range("E9")

    sNomFichierPDF = sNum & "_" & sDate & "_" & sNom & ".pdf"

    ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, Filename:=sNomFichierPDF _
        , Quality:=xlQualityStandard, IncludeDocProperties:=True, IgnorePrintAreas _
        :=False, OpenAfterPublish:=False

Sauver le fichier Excel contenant la macro en xlsm
Voir http://www.developpez.net/forums/d4.../contribuez/excel-vers-pdf-acrobat-distiller/ si ça peut aider
 
Dernière édition:

Vince

XLDnaute Nouveau
Re : Macro Enregistrement PDF

Salut kiki29

J'ai essayé ton code mais sans sucer!

Par contre en réfléchissant un peu j'ai déterminer une forme différente pour arrive a mes fins.

1º - j'enregistre la feuille avec les données de mes cellules dans le dossiers de destination.
2º - j'effectue une impression avec l'imprimante virtuelle d'adobe acrobat qui automatiquement utilise le nom du fichier créer précédemment.

Ainsi j'ai les deux fichiers excell et Pdf. Si j'ai besoin je peu compléter la macro avec la suppression du fichier excell pour seulement avoir le Pdf.

le code:

Sub SauverFichier()
'Date du jour à figer par copier collage spécial
Range("F18").Select
Selection.Copy
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks:=False, Transpose:=False

'Sauvegarde du fichier sous le numéro
Dim D As String
'Dim A As Long, togo As Boolean
Dat = Format(Date, "dd-mm-yyyy")
Chemin = "C:\TEST\"
NomFichier = Range("C18") & " - " & Range("F18") & " - " & Range("E9")
Extantion = ".xlsm"
ThisWorkbook.SaveAs Filename:=Chemin & NomFichier & Extantion

'Convertion en Adobe Acrobat (pdf)
'Boite selection de l'imprimante (option)
'Application.Dialogs(xlDialogPrinterSetup).Show
'Selection de l'imprimante PDF
ActivePrinter = "Adobe Pdf sur Ne04:"
ExecuteExcel4Macro "PRINT(1,,,1,,FALSE,,,,,,2,,,TRUE,,FALSE)"


End Sub
 

kiki29

XLDnaute Barbatruc
Dernière édition:

Manu62

XLDnaute Impliqué
Re : Macro Enregistrement PDF

Bonjour
Ci dessous un code que j'utilise pour enregistrer une feuille ! A adapter sans doute
Il faudra télécherger la dernière version de pdf creator (gratuit)
Code trouver sur excel downloads.
Si tu trouve le code pour remettre l'imprimante de début par défaut, fait nous un retour

Bon courage

'Code pdf pour bon de commande
Private Sub CommandButton70_Click()
'Author : Ken Puls (Excelguru.ca | Tips and pointers for Excel and other MS Office applications)
'Macro Purpose: Print to PDF file using PDFCreator
' (Download from SourceForge.net: PDFCreator)
' Designed for early bind, set reference to PDFCreator
Dim pdfjob As PDFCreator.clsPDFCreator
Dim sPDFName As String
Dim sPDFPath As String
Dim RetVal As Variant
'/// Change the output file name here! ///
Sheets("Bon de Commande").Select 'active la feuille bon de commande
sPDFName = "Q10" ' le nom se trouve en Q10
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("AutosaveDirectory") = Range("Q11") 'le chemin en Q11
.cOption("AutosaveFilename") = Range("Q10") le Nom en Q10
.cOption("AutosaveFormat") = 0 ' 0 = PDF
.cClearCache
End With
'Print the document to PDF
Sheets("Bon de Commande").Select
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
RetVal = Shell("Taskkill /IM PDFCreator.exe /F", 0)
' pdfjob.cClose
'Set pdfjob = Nothing
Sheets("- MENU GENERAL -").Select
End Sub

Manu
 

Discussions similaires

Réponses
22
Affichages
1 K

Membres actuellement en ligne

Statistiques des forums

Discussions
312 177
Messages
2 085 972
Membres
103 073
dernier inscrit
MSCHOE16