Ranjitha
Ranjitha

Reputation: 51

Disable of Page Break display in excel sheet after printing

I have added the pagebreaks between different charts in a excel sheet ,and disabled the display of pagebreaks by using a VBA code. But after printing the charts ,pagebreaks are displayed in a excel sheet . please help me to disable the page breaks display even after printing the charts in VBA.

I have used this code to insert the pagebreaks and disable the display of page breaks

 newch.ResetAllPageBreaks
    newch.Rows(40).PageBreak = xlPageBreakManual
    newch.Rows(71).PageBreak = xlPageBreakManual
    newch.Rows(103).PageBreak = xlPageBreakManual
    newch.Rows(135).PageBreak = xlPageBreakManual

    pageBreakcol = LastCol + 10
    alpha = Col_Letter(CInt(pageBreakcol))
    newch.Columns(alpha).PageBreak = xlPageBreakManual

    'vbreak

    ActiveWindow.View = xlPageBreakPreview
        newch.VPageBreaks(1).DragOff Direction:=xlToRight, RegionIndex:=1
    ActiveWindow.View = xlNormalView 

    Application.PrintCommunication = False
        With newch.PageSetup

            .CenterHorizontally = True
          .CenterVertically = True
        End With
    Application.PrintCommunication = True
    newch.DisplayPageBreaks = False

Upvotes: 0

Views: 477

Answers (1)

ashleedawg
ashleedawg

Reputation: 21639

If you add your own page breaks (for example, with HPageBreak or VPageBreak, or with the Chart.PageSetup Property), it will override the 'ActiveSheet.DisplayPageBreaks = False' setting.

Additionally, from the documentation:

If you add a page break that does not intersect the print area, then the newly-added HPageBreak object will not appear in the HPageBreaks collection for the print area. The contents of the collection may change if the print area is resized or redefined.

(Source)

If you add a page break that does not intersect the print area, then the newly-added VPageBreak object will not appear in the VPageBreaks collection for the print area. The contents of the collection may change if the print area is resized or redefined.

  • For an automatic print area, the VPageBreaks property applies only to the page breaks within the print area.

  • For a user-defined print area of the same range, the VPageBreaks property applies to all of the page breaks.

(Source)

Depending on what you're doing, the PageSetup.PrintArea Property and FitToPages properties might be better suited.

Upvotes: 0

Related Questions