Macro pour imprimer 3 zones mais en différent format

Boostez vos compétences Excel avec notre communauté !

Rejoignez Excel Downloads, le rendez-vous des passionnés où l'entraide fait la force. Apprenez, échangez, progressez – et tout ça gratuitement ! 👉 Inscrivez-vous maintenant !

Beuzzzman

XLDnaute Nouveau
Bonjour,

Voilà donc j'ai 3 feuilles à imprimer qui sont nommer en plage de cellule ( Zone 1, Zone 2 et Zone 3)
Il faut que :
* la Zone 1 soit imprimée en A3 / paysage / zoom à 115%
* la Zone 2 soit imprimée en A4 / paysage / ajuster la feuille à la page
* la Zone 3 soit imprimée en A4 / paysage / ajuster la feuille à la page mais en double

Je sais pas si c'est bien clair si besoin je repréciserais....
On m"a toujours dit sur XL tout est possible, il faut juste savoir comment faire...

Donc une petite macro pour faire ça, Serait ce possible???

J'espère que quelqu'un saura encore me monter que ça lest 😉 😉
 
Re : Macro pour imprimer 3 zones mais en différent format

Bonsoir Beuzzzman,

Une idée qui pourra certainement t'aider efficacement:

Utilise l'enregistreur de macros avec tes différents critères et, si tu obtiendras le code correspondant. Si après celà tu as des questions, tu pourras toujours nous adresser tes macros pour que l'on puisse t'éclairer, mais on aura au moins une base de travail.

Bon courage.

Cordialement.
 
Re : Macro pour imprimer 3 zones mais en différent format

Bonsoir Beuzzzman,

Une idée qui pourra certainement t'aider efficacement:

Utilise l'enregistreur de macros avec tes différents critères et, si tu obtiendras le code correspondant. Si après celà tu as des questions, tu pourras toujours nous adresser tes macros pour que l'on puisse t'éclairer, mais on aura au moins une base de travail.

Bon courage.

Cordialement.

Sub Macro1()
'
' Macro1 Macro
'

'
Application.Goto Reference:="CEP"
Application.PrintCommunication = False
With ActiveSheet.PageSetup
.PrintTitleRows = ""
.PrintTitleColumns = ""
End With
Application.PrintCommunication = True
ActiveSheet.PageSetup.PrintArea = "$N$3:$AI$35"
Application.PrintCommunication = False
With ActiveSheet.PageSetup
.LeftHeader = ""
.CenterHeader = ""
.RightHeader = ""
.LeftFooter = ""
.CenterFooter = ""
.RightFooter = ""
.LeftMargin = Application.InchesToPoints(3.93700787401575E-02)
.RightMargin = Application.InchesToPoints(3.93700787401575E-02)
.TopMargin = Application.InchesToPoints(0.078740157480315)
.BottomMargin = Application.InchesToPoints(0.078740157480315)
.HeaderMargin = Application.InchesToPoints(0)
.FooterMargin = Application.InchesToPoints(0.31496062992126)
.PrintHeadings = False
.PrintGridlines = False
.PrintComments = xlPrintSheetEnd
.PrintQuality = 600
.CenterHorizontally = True
.CenterVertically = True
.Orientation = xlLandscape
.Draft = False
.PaperSize = xlPaperA3
.FirstPageNumber = xlAutomatic
.Order = xlDownThenOver
.BlackAndWhite = False
.Zoom = False
.FitToPagesWide = 1
.FitToPagesTall = 1
.PrintErrors = xlPrintErrorsDisplayed
.OddAndEvenPagesHeaderFooter = False
.DifferentFirstPageHeaderFooter = False
.ScaleWithDocHeaderFooter = True
.AlignMarginsHeaderFooter = True
.EvenPage.LeftHeader.Text = ""
.EvenPage.CenterHeader.Text = ""
.EvenPage.RightHeader.Text = ""
.EvenPage.LeftFooter.Text = ""
.EvenPage.CenterFooter.Text = ""
.EvenPage.RightFooter.Text = ""
.FirstPage.LeftHeader.Text = ""
.FirstPage.CenterHeader.Text = ""
.FirstPage.RightHeader.Text = ""
.FirstPage.LeftFooter.Text = ""
.FirstPage.CenterFooter.Text = ""
.FirstPage.RightFooter.Text = ""
End With
Application.PrintCommunication = True
Application.PrintCommunication = False
With ActiveSheet.PageSetup
.PrintTitleRows = ""
.PrintTitleColumns = ""
End With
Application.PrintCommunication = True
ActiveSheet.PageSetup.PrintArea = "$N$3:$AI$35"
Application.PrintCommunication = False
With ActiveSheet.PageSetup
.LeftHeader = ""
.CenterHeader = ""
.RightHeader = ""
.LeftFooter = ""
.CenterFooter = ""
.RightFooter = ""
.LeftMargin = Application.InchesToPoints(3.93700787401575E-02)
.RightMargin = Application.InchesToPoints(3.93700787401575E-02)
.TopMargin = Application.InchesToPoints(0.078740157480315)
.BottomMargin = Application.InchesToPoints(0.078740157480315)
.HeaderMargin = Application.InchesToPoints(0)
.FooterMargin = Application.InchesToPoints(0.31496062992126)
.PrintHeadings = False
.PrintGridlines = False
.PrintComments = xlPrintSheetEnd
.PrintQuality = 600
.CenterHorizontally = True
.CenterVertically = True
.Orientation = xlLandscape
.Draft = False
.PaperSize = xlPaperA3
.FirstPageNumber = xlAutomatic
.Order = xlDownThenOver
.BlackAndWhite = False
.Zoom = 116
.PrintErrors = xlPrintErrorsDisplayed
.OddAndEvenPagesHeaderFooter = False
.DifferentFirstPageHeaderFooter = False
.ScaleWithDocHeaderFooter = True
.AlignMarginsHeaderFooter = True
.EvenPage.LeftHeader.Text = ""
.EvenPage.CenterHeader.Text = ""
.EvenPage.RightHeader.Text = ""
.EvenPage.LeftFooter.Text = ""
.EvenPage.CenterFooter.Text = ""
.EvenPage.RightFooter.Text = ""
.FirstPage.LeftHeader.Text = ""
.FirstPage.CenterHeader.Text = ""
.FirstPage.RightHeader.Text = ""
.FirstPage.LeftFooter.Text = ""
.FirstPage.CenterFooter.Text = ""
.FirstPage.RightFooter.Text = ""
End With
Application.PrintCommunication = True
Selection.PrintOut Copies:=1, Collate:=True, IgnorePrintAreas:=False
Application.Goto Reference:="MACHINE"
Application.PrintCommunication = False
With ActiveSheet.PageSetup
.PrintTitleRows = ""
.PrintTitleColumns = ""
End With
Application.PrintCommunication = True
ActiveSheet.PageSetup.PrintArea = "$N$3:$AI$35"
Application.PrintCommunication = False
With ActiveSheet.PageSetup
.LeftHeader = ""
.CenterHeader = ""
.RightHeader = ""
.LeftFooter = ""
.CenterFooter = ""
.RightFooter = ""
.LeftMargin = Application.InchesToPoints(3.93700787401575E-02)
.RightMargin = Application.InchesToPoints(3.93700787401575E-02)
.TopMargin = Application.InchesToPoints(0.078740157480315)
.BottomMargin = Application.InchesToPoints(0.078740157480315)
.HeaderMargin = Application.InchesToPoints(0)
.FooterMargin = Application.InchesToPoints(0.31496062992126)
.PrintHeadings = False
.PrintGridlines = False
.PrintComments = xlPrintSheetEnd
.PrintQuality = 600
.CenterHorizontally = True
.CenterVertically = True
.Orientation = xlLandscape
.Draft = False
.PaperSize = xlPaperA4
.FirstPageNumber = xlAutomatic
.Order = xlDownThenOver
.BlackAndWhite = False
.Zoom = 116
.PrintErrors = xlPrintErrorsDisplayed
.OddAndEvenPagesHeaderFooter = False
.DifferentFirstPageHeaderFooter = False
.ScaleWithDocHeaderFooter = True
.AlignMarginsHeaderFooter = True
.EvenPage.LeftHeader.Text = ""
.EvenPage.CenterHeader.Text = ""
.EvenPage.RightHeader.Text = ""
.EvenPage.LeftFooter.Text = ""
.EvenPage.CenterFooter.Text = ""
.EvenPage.RightFooter.Text = ""
.FirstPage.LeftHeader.Text = ""
.FirstPage.CenterHeader.Text = ""
.FirstPage.RightHeader.Text = ""
.FirstPage.LeftFooter.Text = ""
.FirstPage.CenterFooter.Text = ""
.FirstPage.RightFooter.Text = ""
End With
Application.PrintCommunication = True
Application.PrintCommunication = False
With ActiveSheet.PageSetup
.PrintTitleRows = ""
.PrintTitleColumns = ""
End With
Application.PrintCommunication = True
ActiveSheet.PageSetup.PrintArea = "$N$3:$AI$35"
Application.PrintCommunication = False
With ActiveSheet.PageSetup
.LeftHeader = ""
.CenterHeader = ""
.RightHeader = ""
.LeftFooter = ""
.CenterFooter = ""
.RightFooter = ""
.LeftMargin = Application.InchesToPoints(3.93700787401575E-02)
.RightMargin = Application.InchesToPoints(3.93700787401575E-02)
.TopMargin = Application.InchesToPoints(0.078740157480315)
.BottomMargin = Application.InchesToPoints(0.078740157480315)
.HeaderMargin = Application.InchesToPoints(0)
.FooterMargin = Application.InchesToPoints(0.31496062992126)
.PrintHeadings = False
.PrintGridlines = False
.PrintComments = xlPrintSheetEnd
.PrintQuality = 600
.CenterHorizontally = True
.CenterVertically = True
.Orientation = xlLandscape
.Draft = False
.PaperSize = xlPaperA4
.FirstPageNumber = xlAutomatic
.Order = xlDownThenOver
.BlackAndWhite = False
.Zoom = False
.FitToPagesWide = 1
.FitToPagesTall = 1
.PrintErrors = xlPrintErrorsDisplayed
.OddAndEvenPagesHeaderFooter = False
.DifferentFirstPageHeaderFooter = False
.ScaleWithDocHeaderFooter = True
.AlignMarginsHeaderFooter = True
.EvenPage.LeftHeader.Text = ""
.EvenPage.CenterHeader.Text = ""
.EvenPage.RightHeader.Text = ""
.EvenPage.LeftFooter.Text = ""
.EvenPage.CenterFooter.Text = ""
.EvenPage.RightFooter.Text = ""
.FirstPage.LeftHeader.Text = ""
.FirstPage.CenterHeader.Text = ""
.FirstPage.RightHeader.Text = ""
.FirstPage.LeftFooter.Text = ""
.FirstPage.CenterFooter.Text = ""
.FirstPage.RightFooter.Text = ""
End With
Application.PrintCommunication = True
Selection.PrintOut Copies:=1, Collate:=True, IgnorePrintAreas:=False
Application.Goto Reference:="AJOUT"
Selection.PrintOut Copies:=2, Collate:=True, IgnorePrintAreas:=False
End Sub


Par contre quand je l'exécute j'ai une erreur:
 

Pièces jointes

  • bug01.JPG
    bug01.JPG
    21.6 KB · Affichages: 34
  • bug02.jpg
    bug02.jpg
    55.5 KB · Affichages: 39
Re : Macro pour imprimer 3 zones mais en différent format

Bonjour Beuzzman,

Essaie cette version édulcorée de ton code:

Code:
Sub Macro1()
    Application.Goto Reference:="Zone1"
    With ActiveSheet.PageSetup
        .PrintArea = Selection.Address
        .LeftMargin = Application.InchesToPoints(3.93700787401575E-02)
        .RightMargin = Application.InchesToPoints(3.93700787401575E-02)
        .TopMargin = Application.InchesToPoints(0.078740157480315)
        .BottomMargin = Application.InchesToPoints(0.078740157480315)
        .HeaderMargin = Application.InchesToPoints(0)
        .FooterMargin = Application.InchesToPoints(0.31496062992126)
        .PrintQuality = 600
        .CenterHorizontally = True
        .CenterVertically = True
        .Orientation = xlLandscape
        .PaperSize = xlPaperA3
        .FirstPageNumber = xlAutomatic
        .Order = xlDownThenOver
        .Zoom = 115
        .PrintErrors = xlPrintErrorsDisplayed
        .ScaleWithDocHeaderFooter = True
        .AlignMarginsHeaderFooter = True
    End With
    Selection.PrintOut Copies:=1
    
    Application.Goto Reference:="Zone2"
    With ActiveSheet.PageSetup
        .PrintArea = Selection.Address
        .LeftMargin = Application.InchesToPoints(3.93700787401575E-02)
        .RightMargin = Application.InchesToPoints(3.93700787401575E-02)
        .TopMargin = Application.InchesToPoints(0.078740157480315)
        .BottomMargin = Application.InchesToPoints(0.078740157480315)
        .HeaderMargin = Application.InchesToPoints(0)
        .FooterMargin = Application.InchesToPoints(0.31496062992126)
        .PrintComments = xlPrintNoComments
        .PrintQuality = 600
        .CenterHorizontally = True
        .CenterVertically = True
        .Orientation = xlLandscape
        .PaperSize = xlPaperA4
        .FirstPageNumber = xlAutomatic
        .Order = xlDownThenOver
        .Zoom = 100
        .PrintErrors = xlPrintErrorsDisplayed
        .OddAndEvenPagesHeaderFooter = False
        .DifferentFirstPageHeaderFooter = False
        .ScaleWithDocHeaderFooter = True
        .AlignMarginsHeaderFooter = True
    End With
    Selection.PrintOut Copies:=1
    
    Application.Goto Reference:="Zone3"
    With ActiveSheet.PageSetup
        .PrintArea = Selection.Address
        .LeftMargin = Application.InchesToPoints(3.93700787401575E-02)
        .RightMargin = Application.InchesToPoints(3.93700787401575E-02)
        .TopMargin = Application.InchesToPoints(0.078740157480315)
        .BottomMargin = Application.InchesToPoints(0.078740157480315)
        .HeaderMargin = Application.InchesToPoints(0)
        .FooterMargin = Application.InchesToPoints(0.31496062992126)
        .PrintComments = xlPrintNoComments
        .PrintQuality = 600
        .CenterHorizontally = True
        .CenterVertically = True
        .Orientation = xlLandscape
        .PaperSize = xlPaperA4
        .FirstPageNumber = xlAutomatic
        .Order = xlDownThenOver
        .Zoom = 100
        .PrintErrors = xlPrintErrorsDisplayed
        .OddAndEvenPagesHeaderFooter = False
        .DifferentFirstPageHeaderFooter = False
        .ScaleWithDocHeaderFooter = True
        .AlignMarginsHeaderFooter = True
    End With
    Selection.PrintOut Copies:=2
End Sub

N'oublie pas de remplacer les noms de plages (Zone1, Zone2 et Zone3) par ceux de ton application

NB: j'ai supprimé la plupart des instructions écrites par défaut par la macro, et je pense qu'il est possible d'aller encore plus loin. Rien ne t'empêche de faire des essais en ajoutant des ' de commentaires et en testant au fur et à mesure.

A +

Cordialement.
 
Re : Macro pour imprimer 3 zones mais en différent format

RE:

par contre je vois pas de commande pour sélectionner l'imprimante!???
C"est Normal???

Normal, je ne sais pas: sur mon poste, je n'ai qu'une imprimante donc le problème ne s'est pas posé. Si tu en as plusieurs, alors tu peux enregistrer une macro juste pour la séquence de sélection de la machine et tu pourras donc ajouter ce module à la procédure principale.

Restant à ton écoute.

Cordialement.
 
Re : Macro pour imprimer 3 zones mais en différent format

Bonjour Beuzzzman,

Corrige ton code comme ceci:

Code:
Sub Macro1()
    Application.Goto Reference:="Zone1"
    With ActiveSheet.PageSetup
        .PrintArea = Selection.Address
        .LeftMargin = Application.InchesToPoints(3.93700787401575E-02)
        .RightMargin = Application.InchesToPoints(3.93700787401575E-02)
        .TopMargin = Application.InchesToPoints(0.078740157480315)
        .BottomMargin = Application.InchesToPoints(0.078740157480315)
        .HeaderMargin = Application.InchesToPoints(0)
        .FooterMargin = Application.InchesToPoints(0.31496062992126)
        .PrintQuality = 600
        .CenterHorizontally = True
        .CenterVertically = True
        .Orientation = xlLandscape
        .PaperSize = xlPaperA4
        .FirstPageNumber = xlAutomatic
        .Order = xlDownThenOver
        .Zoom = 115
        .PrintErrors = xlPrintErrorsDisplayed
        .ScaleWithDocHeaderFooter = True
        .AlignMarginsHeaderFooter = True
    End With
    Selection.PrintOut Copies:=1
   
    Application.Goto Reference:="Zone2"
    With ActiveSheet.PageSetup
        .PrintArea = Selection.Address
        .LeftMargin = Application.InchesToPoints(3.93700787401575E-02)
        .RightMargin = Application.InchesToPoints(3.93700787401575E-02)
        .TopMargin = Application.InchesToPoints(0.078740157480315)
        .BottomMargin = Application.InchesToPoints(0.078740157480315)
        .HeaderMargin = Application.InchesToPoints(0)
        .FooterMargin = Application.InchesToPoints(0.31496062992126)
        .PrintComments = xlPrintNoComments
        .PrintQuality = 600
        .CenterHorizontally = True
        .CenterVertically = True
        .Orientation = xlLandscape
        .PaperSize = xlPaperA4
        .FirstPageNumber = xlAutomatic
        .Order = xlDownThenOver
        .FitToPagesTall = 1 '-----------------------------Ligne modifiée
        .Zoom = False       '-----------------------------Ligne modifiée
        .PrintErrors = xlPrintErrorsDisplayed
        .OddAndEvenPagesHeaderFooter = False
        .DifferentFirstPageHeaderFooter = False
        .ScaleWithDocHeaderFooter = True
        .AlignMarginsHeaderFooter = True
    End With
    Selection.PrintOut Copies:=1
   
    Application.Goto Reference:="Zone3"
    With ActiveSheet.PageSetup
        .PrintArea = Selection.Address
        .LeftMargin = Application.InchesToPoints(3.93700787401575E-02)
        .RightMargin = Application.InchesToPoints(3.93700787401575E-02)
        .TopMargin = Application.InchesToPoints(0.078740157480315)
        .BottomMargin = Application.InchesToPoints(0.078740157480315)
        .HeaderMargin = Application.InchesToPoints(0)
        .FooterMargin = Application.InchesToPoints(0.31496062992126)
        .PrintComments = xlPrintNoComments
        .PrintQuality = 600
        .CenterHorizontally = True
        .CenterVertically = True
        .Orientation = xlLandscape
        .PaperSize = xlPaperA4
        .FirstPageNumber = xlAutomatic
        .Order = xlDownThenOver
        .FitToPagesTall = 1 '-----------------------------Ligne modifiée
        .Zoom = False       '-----------------------------Ligne modifiée
        .PrintErrors = xlPrintErrorsDisplayed
        .OddAndEvenPagesHeaderFooter = False
        .DifferentFirstPageHeaderFooter = False
        .ScaleWithDocHeaderFooter = True
        .AlignMarginsHeaderFooter = True
    End With
    Selection.PrintOut Copies:=1
End Sub

Cordialement.
 
- Navigue sans publicité
- Accède à Cléa, notre assistante IA experte Excel... et pas que...
- Profite de fonctionnalités exclusives
Ton soutien permet à Excel Downloads de rester 100% gratuit et de continuer à rassembler les passionnés d'Excel.
Je deviens Supporter XLD

Discussions similaires

Réponses
7
Affichages
287
Réponses
7
Affichages
3 K
  • Question Question
Microsoft 365 Règle de 3
Réponses
11
Affichages
832
Retour