+ Reply to Thread
Results 1 to 7 of 7

Cannot force Page Breaks to be calculate

  1. #1
    Registered User
    Join Date
    11-26-2014
    Location
    Aberdeen, Scotland
    MS-Off Ver
    2013
    Posts
    4

    Cannot force Page Breaks to be calculate

    I have code to automate pagination. It's quick and easy, but it Page breaks must be calculated by Excel before it will work. This used to be possible using ActiveWindow.View = xlPageBreakPreview : DoEvents . In the latest version this fails. It feels as though the "optimization" of the screen refresh has killed it. What now happens is that Excel waits until the worksheet is ready for user input and only then triggers a RePaint which will then (if we're in page break preview mode) calculate the page breaks for the sheet. In other words, it cannot be automated. If you make page breaks at an earlier point in the process, then the Repaint will destroy them (because it thinks page breaks have never been calculated). It is not acceptable for me to require users to make manual changes and manually update the page breaks in an automatically generated report. Easiest solution would be to know how to override the optimization and force a page break calculation. Failing that, I could paginate by code but would need to know how to tell Excel that the sheet has had page breaks calculated already.

  2. #2
    Forum Expert mikerickson's Avatar
    Join Date
    03-30-2007
    Location
    Davis CA
    MS-Off Ver
    Excel 2011
    Posts
    6,229

    Re: Cannot force Page Breaks to be calculate

    my double - post
    _
    ...How to Cross-post politely...
    ..Wrap code by selecting the code and clicking the # or read this. Thank you.

  3. #3
    Forum Expert mikerickson's Avatar
    Join Date
    03-30-2007
    Location
    Davis CA
    MS-Off Ver
    Excel 2011
    Posts
    6,229

    Re: Cannot force Page Breaks to be calculate

    What happens if you put this line right after setting the preview.
    Please Login or Register  to view this content.

  4. #4
    Registered User
    Join Date
    11-26-2014
    Location
    Aberdeen, Scotland
    MS-Off Ver
    2013
    Posts
    4

    Re: Cannot force Page Breaks to be calculate

    Screen updating doesn't help. I have tried keeping it at True. I have also tried starting off with a non-blank sheet which has been created manually and has page breaks calculated and is in page break preview mode, then overwriting the data on it using macros. At some point Excel decides that the sheet has never had pages calculated and destroys all hard page breaks (which were correctly set, because I have a call to Sleep inserted so that I can see what's going on without coming into debug mode and making it work because of the manual intervention).

  5. #5
    Forum Expert mikerickson's Avatar
    Join Date
    03-30-2007
    Location
    Davis CA
    MS-Off Ver
    Excel 2011
    Posts
    6,229

    Re: Cannot force Page Breaks to be calculate

    Not keeping it true. But forcing it to run the ScreenUpdate code by forcing it True, even though it is already.

    I had an issue where moving a shape wouldn't be seen until the End Sub ran. Putting an unnecessary ScreenUpdating = True fixed that.
    Perhaps an unnecessary ScreenUpdating = True will fix your issue.

  6. #6
    Registered User
    Join Date
    11-26-2014
    Location
    Aberdeen, Scotland
    MS-Off Ver
    2013
    Posts
    4

    Re: Cannot force Page Breaks to be calculate

    Code now reads
    Application.ScreenUpdating = True: DoEvents
    ActiveWindow.View = xlPageBreakPreview ' or page breaks don't recalculate
    Application.ScreenUpdating = True
    DoEvents
    but it makes no difference. Pagebreaks become valid only when the sheet is waiting for input

  7. #7
    Registered User
    Join Date
    11-26-2014
    Location
    Aberdeen, Scotland
    MS-Off Ver
    2013
    Posts
    4

    Re: Cannot force Page Breaks to be calculate

    I have also wondered if it might be due to multi-threading (my repaginating code running in one thread while Excel is trying to calculate the page breaks), but inserting
    Application.MultiThreadedCalculation.Enabled = false
    before all the above code doesn't help either.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Clear all page breaks, then insert new breaks at change in data
    By Alex0929 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 09-09-2014, 03:12 PM
  2. Removing Existing Page Breaks and Inserting a Page Break every third Total Line
    By Kalvas in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 09-17-2013, 05:12 AM
  3. Replies: 1
    Last Post: 03-15-2009, 06:08 PM
  4. Hard page breaks being replaced by soft breaks in the wrong place
    By JDavies in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 11-14-2008, 10:28 AM
  5. Print Breaks-Automatic or Force New
    By Tracy in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 03-22-2006, 08:20 PM

Tags for this Thread

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