+ Reply to Thread
Results 1 to 13 of 13

Remove Any Pagebreaks

Hybrid View

  1. #1
    Registered User
    Join Date
    09-03-2007
    Posts
    51

    Remove Any Pagebreaks

    I'm using the this code to print some info out of an existing worksheet and I'd like to force excel to remove all pagebreaks, as the last column or two is always printed onto another page. Does anyone know how to programatically remove pagebreaks?

    Sub PrintSelectedRows()
    Dim trow As Integer
    Dim brow As Integer
    Dim x As Integer
        Application.ScreenUpdating = False
        currentsheet = ActiveSheet.Name
        trow = Selection.Row
        brow = Selection.Rows.Count + trow - 1
        Range("A1:E8").Copy
    Set Newsheet = Worksheets.Add
        Selection.PasteSpecial Paste:=xlAll
        Worksheets(currentsheet).Range("A" & trow & ":E" & brow).Copy
        With Newsheet
            .Range("A9").PasteSpecial Paste:=xlPasteAll
            .Range("A9").PasteSpecial Paste:=xlPasteColumnWidths
            .PageSetup.PrintArea = "$A$1:$E$35"
            .PrintOut
            .Delete
        End With
        Worksheets(currentsheet).Activate
        Application.ScreenUpdating = True
    End Sub

  2. #2
    Forum Expert dominicb's Avatar
    Join Date
    01-25-2005
    Location
    Lancashire, England
    MS-Off Ver
    MS Office 2000, 2003, 2007 & 2016 365
    Posts
    4,867

    Smile

    Good morning Gordon@work

    How about something like this :

    Sub test()
    Cells.PageBreak = xlPageBreakNone
    End Sub
    HTH

    DominicB
    Please familiarise yourself with the rules before posting. You can find them here.

  3. #3
    Registered User
    Join Date
    09-03-2007
    Posts
    51

    Cells.PageBreak = xlPageBreakNone

    That causes an error saying: Unable to set the pagebreak property for the range class
    I tried another line which doesn't cause an error, I think because it's concerning the actual location of the break, but it just doesn't do anything at all: Columns("B:C").PageBreak = xlPageBreakNone

  4. #4
    Valued Forum Contributor
    Join Date
    04-11-2006
    Posts
    407
    If you just want it to print on one page maybe this would suffice:
    With ThisWorkbook.ActiveSheet.PageSetup
        .Zoom = False
        .FitToPagesWide = 1
        .FitToPagesTall = 1
    End With

  5. #5
    Registered User
    Join Date
    09-03-2007
    Posts
    51

    PageSetup method

    Thanks Ikaabod.
    It doesn't generate an error, but still prints the last column on a separate page.
    I've tried it from two other people's machines and we all have the same problem, this is infuriating.

  6. #6
    Forum Expert dominicb's Avatar
    Join Date
    01-25-2005
    Location
    Lancashire, England
    MS-Off Ver
    MS Office 2000, 2003, 2007 & 2016 365
    Posts
    4,867

    Smile

    Hi Gordon@work

    Quote Originally Posted by Gordon@work
    That causes an error saying: Unable to set the pagebreak property for the range class
    That's strange. It works just fine for me.

    Sticking with the one liners, try this :
    Sub test()
    Application.Worksheets("Sheet1").ResetAllPageBreaks
    End Sub
    (obviously, you replace "Sheet1 with your sheet name"

    HTH

    DominicB

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1