Sortie vers fichier PDF

kadelmalin

XLDnaute Occasionnel
Bonjour le forum,
je souhaite votre aide pour envoyer avec macro une plage de cellules vers un fichier pdf. je joins le classeur teste. Merci beaucoup de votre assistance.
 

Pièces jointes

  • Formulaire.xlsx
    21.4 KB · Affichages: 35

job75

XLDnaute Barbatruc
Bonsoir,

Pourquoi un fichier sur cjoint Abdelkader ?

Et pourquoi compliquer la macro ? Créer un PDF c'est rien du tout :
Code:
Sub PDF()
ActiveSheet.ExportAsFixedFormat xlTypePDF, ThisWorkbook.Path & "\Formulaire.pdf", Quality:=xlQualityStandard
End Sub
Bonne nuit.
 

Pièces jointes

  • Formulaire(1).xlsm
    30.1 KB · Affichages: 30

kadelmalin

XLDnaute Occasionnel
Re Bonjour,
J'ai adapté votre solution à mon code et je vous en remercie. Est il possible de limiter le pdf à une zone sélectionnée; voici mon code :
Sub Sauve_Doc()
If Range("$P$5").Value = 1 Then
Range("C2:M40").Select
ActiveSheet.ExportAsFixedFormat xlTypePDF, ThisWorkbook.Path & "\JRN.pdf", Quality:=xlQualityStandard
ElseIf Range("$P$5").Value = 2 Then
Range("C2:M86").Select
ActiveSheet.ExportAsFixedFormat xlTypePDF, ThisWorkbook.Path & "\JRN.pdf", Quality:=xlQualityStandard
ElseIf Range("$P$5").Value = 3 Then
Range("C2:M132").Select
ActiveSheet.ExportAsFixedFormat xlTypePDF, ThisWorkbook.Path & "\JRN.pdf", Quality:=xlQualityStandard
ElseIf Range("$P$5").Value = 4 Then
Range("C2:M178").Select
ActiveSheet.ExportAsFixedFormat xlTypePDF, ThisWorkbook.Path & "\JRN.pdf", Quality:=xlQualityStandard
ElseIf Range("$P$5").Value = 5 Then
Range("C2:M224").Select
ActiveSheet.ExportAsFixedFormat xlTypePDF, ThisWorkbook.Path & "\JRN.pdf", Quality:=xlQualityStandard
End If
Range("A1").Select
End Sub
Merci de m'avoir consacré votre temps.
 

job75

XLDnaute Barbatruc
Bonsoir kadelmalin,

Je n'avais pas vu votre dernier post.

Ce qu'il faut c'est définir la zone d'impression pour les 5 valeurs de P5 :
Code:
Sub Sauve_Doc()
If IsError(Application.Match([P5], Array(1, 2, 3, 4, 5), 0)) Then Exit Sub
ActiveSheet.PageSetup.PrintArea = "C2:M" & 46 * [P5] - 6 'définit la zone d'impression
ActiveSheet.ExportAsFixedFormat xlTypePDF, ThisWorkbook.Path & "\JRN.pdf", Quality:=xlQualityStandard
End Sub
PS : En VBA les Select sont en général inutiles, voire nuisibles.

A+
 

Discussions similaires