Décalage numérotation page

Bonjour à tous,

Encore un petit problème sur ma macro,

Je dois imprimer l'ensemble de mes onglets sauf le premier, jusque là pas de problème,

Sur chaque onglet j'imprime les lignes 1 à 32 puis 33 à 64 ect.... mais le numero de mes page se décale, j'ai rien en page 1, j'ai la page 1/x à la seconde 2/x sur la suivante ect..., puis je passe à l'onglet d’après et la première page à comme numéro la x/x.....

Sub AllPrint() 'Bouton Impression
Dim a, c, b As Long
Dim k, m, NbPages As Long

On Error Resume Next
Application.Dialogs(xlDialogPrinterSetup).Show
x = Sheets.Count

For i = 2 To x

    With Sheets(i)
    .Select

        a = Range("B65536").End(xlUp).Row 
        NbPages = ((a + 15) / 32) 'ici je dertermine le nombre de page totale

    For m = 1 To a Step 32
        k = m + 31
        If k > a Then k = a
        b = (k / 31) ' ici la page active

        ActiveSheet.PageSetup.CenterHeaderPicture.Filename = _
            "F:\Saint Louis\Glims\Masque logo.GIF"
        ActiveSheet.PageSetup.CenterFooterPicture.Filename = _
            "F:\Saint Louis\Glims\Masque Pied.GIF"

             With ActiveSheet.PageSetup.CenterHeaderPicture
                .Height = 69
                .Width = 584.2
            End With
            With ActiveSheet.PageSetup.CenterFooterPicture

            .Height = 42
            .Width = 450
            End With

    Application.PrintCommunication = True
    ActiveSheet.PageSetup.PrintArea = "A1:E" & a & ""
    Application.PrintCommunication = False
        With ActiveSheet.PageSetup
        .HeaderMargin = Application.InchesToPoints(0.1)
        .FooterMargin = Application.InchesToPoints(0.1)
        .CenterHeader = "&G" '
        .CenterFooter = "&G"
        .RightFooter = ""
        .RightFooter = Cells(13, 3) & Chr(10) & "Page  " & b & " / " & NbPages & ""
        .CenterHorizontally = True
        .FitToPagesWide = 1
        .Orientation = xlLandscape
        .ScaleWithDocHeaderFooter = True
        .AlignMarginsHeaderFooter = True
       Rows(m & ":" & k).PrintOut
        End With

     Next m
    End With

Next i
'
End Sub

Si vous avez des idées je suis prenneur,

Merci pour vos idées

3decalage-page.xlsm (74.59 Ko)

Salut edlede,

pas d'imprimante sous la main, pas pu tester ma version reconstruite après 'codage-test décortiqué'...

Je calcule 'a' sur la colonne E, la plus représentative, en espérant que toutes tes feuilles aient la même structure...

Bref, à tester...

Sub AllPrint() 'Bouton Impression
'
Dim a, c, b As Integer
Dim k, m, NbPages As Integer
'
On Error Resume Next
Application.Dialogs(xlDialogPrinterSetup).Show
'
For i = 1 To Sheets.Count
    If Sheets(i).Name <> "Non imprimable" Then
    sWks = Sheets(i).Name
    k = 0
    With Worksheets(sWks)
        a = .Cells(Rows.Count, 5).End(xlUp).Row
        NbPages = IIf(a Mod 32 = 0, a / 32, Int(a / 32) + 1)
        '
        For m = 1 To NbPages
            k = IIf(k > a, a, m * 32)
            kk = 1 + ((m - 1) * 32)
            '
            ActiveSheet.PageSetup.CenterHeaderPicture.Filename = _
            "F:\Saint Louis\Glims\Masque logo.GIF"
            ActiveSheet.PageSetup.CenterFooterPicture.Filename = _
            "F:\Saint Louis\Glims\Masque Pied.GIF"
            '
            With ActiveSheet.PageSetup.CenterHeaderPicture
                .Height = 69
                .Width = 584.2
            End With
            With ActiveSheet.PageSetup.CenterFooterPicture
                .Height = 42
                .Width = 450
            End With
            '
            Application.PrintCommunication = True
            ActiveSheet.PageSetup.PrintArea = "A1:E" & a & ""
            Application.PrintCommunication = False
            With ActiveSheet.PageSetup
                .HeaderMargin = Application.InchesToPoints(0.1)
                .FooterMargin = Application.InchesToPoints(0.1)
                .CenterHeader = "&G" '
                .CenterFooter = "&G"
                .RightFooter = ""
                .RightFooter = Cells(13, 3) & Chr(10) & "Page  " & m & " / " & NbPages & ""
                .CenterHorizontally = True
                .FitToPagesWide = 1
                .Orientation = xlLandscape
                .ScaleWithDocHeaderFooter = True
                .AlignMarginsHeaderFooter = True
                Rows(kk & ":" & k).PrintOut
            End With
        Next m
        '
    End With
Next i
'
End Sub

A+

Merci je viens de trouver l'erreur dans mon code grâce au tien ( une erreur de copier/coller de ton code vers le mien)

il suffit de dégager

 Application.PrintCommunication = True
            ActiveSheet.PageSetup.PrintArea = "A1:E" & a & ""
            Application.PrintCommunication = False

et ça fonctionne nickel, par contre j'ai pas compris pourquoi ! Et ton code fonctionne aussi si on retire bout de code

Cool merci

à bientôt

Rechercher des sujets similaires à "decalage numerotation page"