Microsoft 365 Macro VBA impression automatique

Clément_1728

XLDnaute Nouveau
bonjour,

Je souhaite savoir s'il est possible de créer un bouton permettant d'imprimer plusieurs onglets d'un fichier excel.

Le premier onglet serait à imprimer au format A4
le deuxième au format A3
et le troisième au format A4, tout en ajustant la page au format.
 

fanch55

XLDnaute Barbatruc
Bonjour,
Il y a plein d'exemple sur la toile .
Voici un code adapté :
VB:
Sub Imprimer()
    Application.PrintCommunication = False
    
    On Error Resume Next
    
    With ThisWorkbook.Worksheets("Feuil1").PageSetup
        .PrintArea = ""
        .Orientation = xlPortrait
        .PaperSize = xlPaperA4
        .Parent.PrintPreview
    End With
    With ThisWorkbook.Worksheets("Feuil2").PageSetup
        .PrintArea = ""
        .Orientation = xlPortrait
        Application.PrintCommunication = True
            .PaperSize = xlPaperA3
            If Err Then
                .PaperSize = xlPaperA4
                MsgBox "Format A3 non supporté" & vbLf & vbLf & "A4 établi", vbCritical + vbOKOnly
                Err.Clear
            End If
        Application.PrintCommunication = False
       .Parent.PrintPreview
    End With
    With ThisWorkbook.Worksheets("Feuil3").PageSetup
        .PrintArea = ""
        .Orientation = xlPortrait
        .PaperSize = xlPaperA4
        .FitToPagesWide = 1: .CenterHorizontally = True
        .FitToPagesTall = 1: .CenterVertically = True:
        .Parent.PrintPreview
    End With
    
    Application.PrintCommunication = True
    
End Sub
 

Phil69970

XLDnaute Barbatruc
Bonjour @Clément_1728, @fanch55

Il y a plein d'exemple sur la toile .
Tout à fait d'accord avec toi.
Il suffit de regarder en bas de la discussion

1626949376610.png


Et j'avais fait ceci en octobre 2020 voir ici sans aucun retour de @Julien_m le demandeur 😭

@Phil69970
 

Discussions similaires

Réponses
8
Affichages
490