Programmation des marges de page dans le code

Bonjour Forum,

Chers membres du forum, quel est le code pour les marges de la page suivante?

Gauche,Droite,Haut et Bas 0.5

En tete et pied de page 0

Et où puis-je le mettre dans ce code ?

With ActiveSheet
    .PageSetup.Zoom = False
    .PageSetup.FitToPagesTall = 1 '1 page en hauteur, détermine le zoom
  If rep = 6 Then 'Oui
        a = .PageSetup.PrintArea
        h = .Range(a).Rows.Count
        .Copy 'nouveau document
        With ActiveSheet
            .PageSetup.PrintArea = ""
            For i = 1 To Val(.[M1] - 1)
                .Range(a).EntireRow.Offset(h * i - h).Copy .[A1].Offset(h * i)
                .[A9].Offset(h * i) = i + 1
                .HPageBreaks.Add Before:=.[A1].Offset(h * i) 'saut de page
            Next
            .PageSetup.PrintArea = .Range(a).Resize(h * i).Address
            .PageSetup.FitToPagesTall = i
            .ExportAsFixedFormat xlTypePDF, chemin & "GroupéListeSalles.pdf"
            .Parent.Close False 'fermeture du document
        End With

Merci.

bonjour,

un essai sans fichier

     With ActiveSheet
          If rep = 6 Then     'Oui
               a = .PageSetup.PrintArea
               h = .Range(a).Rows.Count
               .Copy     'nouveau document

               With ActiveSheet
                    For i = 1 To Val(.[M1] - 1)
                         .Range(a).EntireRow.Offset(h * i - h).Copy .[A1].Offset(h * i)
                         .[A9].Offset(h * i) = i + 1
                         .HPageBreaks.Add Before:=.[A1].Offset(h * i)     'saut de page
                    Next

                    With .PageSetup
                         .Zoom = False
                         .LeftMargin = Application.CentimetersToPoints(0.5)
                         .RightMargin = Application.CentimetersToPoints(0.5)
                         .TopMargin = Application.CentimetersToPoints(0.5)
                         .BottomMargin = Application.CentimetersToPoints(0.5)
                         .HeaderMargin = Application.CentimetersToPoints(0)
                         .FooterMargin = Application.CentimetersToPoints(0)
                         .PageSetup.PrintArea = .Range(a).Resize(h * i).Address
                         .PageSetup.FitToPagesTall = i
                         .PrintArea = ""
                    End With

                    .ExportAsFixedFormat xlTypePDF, chemin & "GroupéListeSalles.pdf"
                    .Parent.Close False     'fermeture du document
               End With

          End If
     End With

Merci BsLav

il donne erreur else sans if

bonjour,

je ne vois pas un "else" dans ma code, donc il faut voire tout le code.

Merci de votre intérêt.

Tout le code:

Sub imprimer_formatpdf()
If Not ActiveSheet.Name Like "LS*" Then Exit Sub 'sécurité
Dim chemin$, rep As Byte, a$, h&, i&
chemin = ThisWorkbook.Path & "\ListeSalles\"
If Dir(chemin, vbDirectory) = "" Then MkDir chemin 'création du dossier

        MsgBox "ListeSalles åÔÇã:Êã ÅäÔÇÁ ãáÝ ÇáÍÝÙ "

rep = MsgBox("åá ÊÑíÏ(íä)ÍÝÙ áæÇÆÍ ÇáÞÇÚÇÊ ãÌÊãÚÉ Ýí ãáÝ ÈÏÅÝ æÇÍÏ¿", 3)
If rep = 2 Then Exit Sub
Application.ScreenUpdating = False
     With ActiveSheet
          If rep = 6 Then     'Oui
               a = .PageSetup.PrintArea
               h = .Range(a).Rows.Count
               .Copy     'nouveau document

               With ActiveSheet
                    For i = 1 To Val(.[M1] - 1)
                         .Range(a).EntireRow.Offset(h * i - h).Copy .[A1].Offset(h * i)
                         .[A9].Offset(h * i) = i + 1
                         .HPageBreaks.Add Before:=.[A1].Offset(h * i)     'saut de page
                    Next

                    With .PageSetup
                         .Zoom = False
                         .LeftMargin = Application.CentimetersToPoints(0.5)
                         .RightMargin = Application.CentimetersToPoints(0.5)
                         .TopMargin = Application.CentimetersToPoints(0.5)
                         .BottomMargin = Application.CentimetersToPoints(0.5)
                         .HeaderMargin = Application.CentimetersToPoints(0)
                         .FooterMargin = Application.CentimetersToPoints(0)
                         .PageSetup.PrintArea = .Range(a).Resize(h * i).Address
                         .PageSetup.FitToPagesTall = i
                         .PrintArea = ""
                    End With

                    .ExportAsFixedFormat xlTypePDF, chemin & "GroupéListeSalles.pdf"
                    .Parent.Close False     'fermeture du document
               End With

          End If
     End With

      MsgBox i & " :ÚÏÏ áæÇÆÍ ÇáÞÇÚÇÊ ÇáãÌÊãÚÉ ÈÏÅÝ ÇáÊí Êã ÍÝÙåÇ ÈäÌÇÍ åæ"

  Else 'Non
        For i = 1 To Val(.[M1])
            .[A9] = i
            .ExportAsFixedFormat xlTypePDF, chemin & .[A9] & "_" & "Salle" & ".pdf"
        Next
        .[A9] = 1
        MsgBox i - 1 & " :ÚÏÏ áæÇÆÍ ÇáÞÇÚÇÊ ÇáãÊÝÑÞÉ ÈÏÅÝ ÇáÊí Êã ÍÝÙåÇ ÈäÌÇÍ åæ"
  End If
End With
End Sub

bonjour, nouveau essai

Sub imprimer_formatpdf()
     If Not ActiveSheet.Name Like "LS*" Then Exit Sub     'sécurité
     Dim chemin$, rep As Byte, a$, h&, i&
     chemin = ThisWorkbook.Path & "\ListeSalles\"
     If Dir(chemin, vbDirectory) = "" Then MkDir chemin     'création du dossier

     MsgBox "ListeSalles åÔÇã:Êã ÅäÔÇÁ ãáÝ ÇáÍÝÙ "

     rep = MsgBox("åá ÊÑíÏ(íä)ÍÝÙ áæÇÆÍ ÇáÞÇÚÇÊ ãÌÊãÚÉ Ýí ãáÝ ÈÏÅÝ æÇÍÏ¿", 3)
     If rep = 2 Then Exit Sub
     Application.ScreenUpdating = False
     With ActiveSheet

          If rep = 6 Then     'Oui
               a = .PageSetup.PrintArea
               h = .Range(a).Rows.Count
               .Copy     'nouveau document

               With ActiveSheet
                    With .PageSetup     'setup pour la nouvelle feuille
                         .Zoom = False
                         .LeftMargin = Application.CentimetersToPoints(0.5)
                         .RightMargin = Application.CentimetersToPoints(0.5)
                         .TopMargin = Application.CentimetersToPoints(0.5)
                         .BottomMargin = Application.CentimetersToPoints(0.5)
                         .HeaderMargin = Application.CentimetersToPoints(0)
                         .FooterMargin = Application.CentimetersToPoints(0)
                    End With

                    For i = 1 To Val(.[M1] - 1)
                         .Range(a).EntireRow.Offset(h * i - h).Copy .[A1].Offset(h * i)
                         .[A9].Offset(h * i) = i + 1
                         .HPageBreaks.Add Before:=.[A1].Offset(h * i)     'saut de page
                    Next
                    With .PageSetup
                         .FitToPagesTall = i
                         .PrintArea = .Range(a).Resize(h * i).Address
                    End With
                    .ExportAsFixedFormat xlTypePDF, chemin & "GroupéListeSalles.pdf"
                    .Parent.Close False     'fermeture du document
               End With

               MsgBox i & " :ÚÏÏ áæÇÆÍ ÇáÞÇÚÇÊ ÇáãÌÊãÚÉ ÈÏÅÝ ÇáÊí Êã ÍÝÙåÇ ÈäÌÇÍ åæ"

          Else     'Non
               For i = 1 To Val(.[M1])
                    .[A9] = i
                    .ExportAsFixedFormat xlTypePDF, chemin & .[A9] & "_" & "Salle" & ".pdf"
               Next
               .[A9] = 1
               MsgBox i - 1 & " :ÚÏÏ áæÇÆÍ ÇáÞÇÚÇÊ ÇáãÊÝÑÞÉ ÈÏÅÝ ÇáÊí Êã ÍÝÙåÇ ÈäÌÇÍ åæ"
          End If
     End With
End Sub
Rechercher des sujets similaires à "programmation marges page code"