Archiver en pdf

lioneldu47

XLDnaute Occasionnel
Bonjour le forum,​

J'ai un petit problème pour enregistrer en pdf une feuille excel. J'arrive à le faire à l'aide d'une macro mais mon problème est pour le nom du fichier.Je n'arrive pas à le changer. J'aimerais que le nom du fichier prenne la valeur de deux cases par exemple D3 et D4. Ces valeurs changent à chaque fois...
Voici ma macro qui fonctionne mais toujours avec le même nom...

Sub Archiver1()
Range("C1:I58").Select
AL = Range("F3,I33")
ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, Filename:= _
"C:\Documents and Settings\pascal\Bureau\Archive Facture\1.pdf", Quality _
:=xlQualityStandard, IncludeDocProperties:=True, IgnorePrintAreas:=False, _
OpenAfterPublish:=False
End Sub

En rouge est le nom que je veux changer par la valeur d'une case...

Merci pour votre aide:D
 

pierre93

XLDnaute Nouveau
Re : Archiver en pdf

Salut,

Pour enregistrer en PDF voici la macro que j'utilise, en rouge les paramètres qui devraient t'aider :

Sub ToPdf()

Set pdfjob = CreateObject("PDFCreator.clsPDFCreator")
NomExcel = Range("K1")
NomPdf = Left(NomExcel, Len(NomExcel) - 0) & ".pdf"
With pdfjob
If .cstart("/NoProcessingAtStartup") = False Then
MsgBox "Can't initialize PDFCreator.", vbCritical + vbOKOnly, "PrtPDFCreator"
Exit Sub
End If
.cOption("UseAutosave") = 1
.cOption("UseAutisaveDirectory") = 1
.cOption("AutosaveDirectory") = ThisWorkbook.Path
.cOption("AutosaveFilename") = NomPdf
.cOption("AutosaveFormat") = 0
.cClearCache
End With
Range("A1:H18").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

End Sub
 

Manu62

XLDnaute Impliqué
Re : Archiver en pdf

Bonjour,

Moi j'utilise le code suivant et il marche nikel...
Vérifie que dans les références, pdfcreator soit cocher. version de pdf creator utilisé = 0.9.8. la 0.9.9 est dispo il me semble


Sub CommandButton32_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("ta feuille").Select
sPDFName = "R6" 'ici la cellule du nom de fichier
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("R7") 'ici la cellule sur le chemin
.cOption("AutosaveFilename") = Range("R6") ' ici la cellule sur le nom du fichier
.cOption("AutosaveFormat") = 0 ' 0 = PDF
.cClearCache
End With
'Print the document to PDF
Sheets("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
End Sub

Voila

Manu
 

klin89

XLDnaute Accro
Re : Archiver en pdf

Bonjour le forum,
Bonjour pierre93, lioneldu47, Manu62

Tu n'as pas oublié de déclarer ceci :

Code:
[COLOR="DarkGreen"]'Dim pdfjob As PDFCreator.clsPDFCreator[/COLOR]
Dim pdfjob As Object 'liaison tardive

Klin89

Question : PDFCreator est-il installé chez toi ? :rolleyes:
 
Dernière édition:

Manu62

XLDnaute Impliqué
Re : Archiver en pdf

Bonjour,

en bas à droite, as tu un bouton rouge pdf......

si oui, clic droit et quitte.

j'avais eu la même chose, et apres c'est ok normalement

as tu bien activer la reference ?
A+

Manu

As tu laisser le code ci dessous en vert (extrati)

' pdfjob.cClose
'Set pdfjob = Nothing
 

Discussions similaires

Statistiques des forums

Discussions
312 299
Messages
2 086 986
Membres
103 419
dernier inscrit
mk29