+ Reply to Thread
Results 1 to 10 of 10

Collapsed Section / Hidden page, prints as a blank page

  1. #1
    Forum Contributor
    Join Date
    11-26-2008
    Location
    Ohio
    MS-Off Ver
    2016
    Posts
    326

    Collapsed Section / Hidden page, prints as a blank page

    Hi,
    I have some code that "expands / collapses" a page in a sheet. (Page #2 hides, or is viewable with a button click)
    It works fine, but when I print, or print preview, page #2 still shows / prints, as a blank page.
    I would want any "collapsed pages" not to print. Can someone help with this.
    I attached a sample sheet of what I'm doing.
    Excel 2016
    Attached Files Attached Files

  2. #2
    Forum Expert Greg M's Avatar
    Join Date
    08-16-2007
    Location
    Dublin. Ireland
    MS-Off Ver
    Office 2016
    Posts
    4,481

    Re: Collapsed Section / Hidden page, prints as a blank page

    Hi there,

    You're displaying/hiding the required rows all right, but the manual (horizontal) PageBreaks are still there, and these are what give rise to the empty pages when printing.

    Your toggling routine also needs to insert/remove PageBreaks to avoid the empty pages - see if the following code does what you need:

    Please Login or Register  to view this content.
    The highlighted values may be altered to suit your requirements.


    Hope this helps - please let me know how you get on.

    Regards,

    Greg M

  3. #3
    Forum Contributor
    Join Date
    11-26-2008
    Location
    Ohio
    MS-Off Ver
    2016
    Posts
    326

    Re: Collapsed Section / Hidden page, prints as a blank page

    Thank you Greg. Yes this works fine, but when I altered the code for the "real sheet" (Adding pages)
    It does not work. I'm sure I am doing something wrong.
    The final code would be used to "expand / collapse" pages 4 through 30. (I can edit the code for lines collapsed).
    Would it be asking too much to have you do that code for me?
    Sorry, but I'm bad at coding.
    Regards / Richard

  4. #4
    Forum Contributor
    Join Date
    11-26-2008
    Location
    Ohio
    MS-Off Ver
    2016
    Posts
    326

    Re: Collapsed Section / Hidden page, prints as a blank page

    Even if you could do a few more page, I can then see the differences, and then attempt to do it myself.
    Thanks Again.

  5. #5
    Forum Expert Greg M's Avatar
    Join Date
    08-16-2007
    Location
    Dublin. Ireland
    MS-Off Ver
    Office 2016
    Posts
    4,481

    Re: Collapsed Section / Hidden page, prints as a blank page

    Hi again Richard,

    Ok, thanks for your feedback.

    Two questions:

    You suggest that you'll need to be able to toggle Pages 4 - 30. It definitely makes life easier if you don't need to toggle Page 1 - can you confirm that this is the case?

    How to you intend to call the various toggling routines? Will you have a different button for each page? Will you call them from the Macro menu (Alt+F8)? Would it be useful to have a cell with a 4-30 dropdown list from which the number of the page to be toggled could be selected? Some other method?

    The answer to the second question will probably have a significant effect on the choice of the coding involved.

    Regards,

    Greg M

  6. #6
    Forum Contributor
    Join Date
    11-26-2008
    Location
    Ohio
    MS-Off Ver
    2016
    Posts
    326

    Re: Collapsed Section / Hidden page, prints as a blank page

    Yes, Pages 1-3 will not need to have toggles. Then there may be about 6 or 8 pages that have toggles to "open or collapse" them.
    The method of "toggling", I was thinging of just having a button, (just off the page on the lower right) to open and close.
    I attached a workbook here of what I'm thinking, take a look. Also note, I was able to edit your code a bit to change and add pages.
    It works ok with ONE EXCEPTION. Edited, I still have problems on some pages where the collapsed pages still show as "blank pages"
    when printed. (I'm sure i'm screwing up the code changes but take a look at it.)
    Attached Files Attached Files

  7. #7
    Forum Contributor
    Join Date
    11-26-2008
    Location
    Ohio
    MS-Off Ver
    2016
    Posts
    326

    Re: Collapsed Section / Hidden page, prints as a blank page

    Also, the "4-30 dropdown list" you mention is intriguing. (may be good). Is that something that could be on, say, page two.
    (I would not mind seeing a sample of what that would be like).
    The wookbook is a report of about 30 page, and sometimes I need a few "extra pages". (thus the toggled pages)
    There is also an "Index of pages"

  8. #8
    Forum Expert Greg M's Avatar
    Join Date
    08-16-2007
    Location
    Dublin. Ireland
    MS-Off Ver
    Office 2016
    Posts
    4,481

    Re: Collapsed Section / Hidden page, prints as a blank page

    Hi again Richard,

    Take a look at the attached workbook and see if it gets you moving in the right direction.

    The main worksheet contains ten page ranges, all of which are "collapsible" except for the first one.

    Page ranges are toggled by selecting a page number / page title from the dropdown list of a ComboBox located beside the first page range - having the page title available is probably a bit more intuitive than having to remember which page number refers to which information.

    The following code is inserted in the VBA CodeModule for the main worksheet:

    Please Login or Register  to view this content.
    and the following code in a standard VBA CodeModule:

    Please Login or Register  to view this content.
    The highlighted values may be altered to suit your requirements.


    Hope this helps - please let me know how you get on.

    Regards,

    Greg M
    Attached Files Attached Files
    Last edited by Greg M; 10-25-2019 at 11:42 AM. Reason: Typo corrected

  9. #9
    Forum Contributor
    Join Date
    11-26-2008
    Location
    Ohio
    MS-Off Ver
    2016
    Posts
    326

    Re: Collapsed Section / Hidden page, prints as a blank page

    Wow, That's cool, but I dont think that will work for me in this report.

    If you would be so kind as to just edit your previous code, (below) so that I can "toggle / collapse"
    pages; 6, 9, 12, 17, 20, 21, 24, that would be a great help.
    Thanks again for all your help. (I have to learn more about coding!)


    [code]
    Option Explicit


    '=========================================================================================
    '=========================================================================================


    Const msPAGE_1 As String = "1:20"
    Const msPAGE_2 As String = "21:40"
    Const msPAGE_3 As String = "41:60"


    '=========================================================================================
    '=========================================================================================


    Sub TogglePage_1()

    Call TogglePage(sPage:=msPAGE_1)

    ' If the range being toggled is Page 1, then the PageBreak to be toggled is on Page 2
    If ActiveSheet.Range(msPAGE_1).EntireRow.Hidden = True Then
    Call PageBreakIsInserted(sPage:=msPAGE_2, bTrueorFalse:=False)
    Else: Call PageBreakIsInserted(sPage:=msPAGE_2, bTrueorFalse:=True)
    End If

    End Sub


    '=========================================================================================
    '=========================================================================================


    Sub TogglePage_2()

    Call TogglePage(sPage:=msPAGE_2)

    End Sub


    '=========================================================================================
    '=========================================================================================


    Sub TogglePage_3()

    Call TogglePage(sPage:=msPAGE_3)

    End Sub


    '=========================================================================================
    '=========================================================================================


    Private Sub TogglePage(sPage As String)

    Dim rPage As Range
    Dim wks As Worksheet

    Set wks = ActiveSheet

    With wks

    .Range(msPAGE_2).Rows(1).EntireRow.PageBreak = xlPageBreakManual
    .Range(msPAGE_3).Rows(1).EntireRow.PageBreak = xlPageBreakManual

    Set rPage = .Range(sPage)

    End With

    With rPage

    .EntireRow.Hidden = Not .EntireRow.Hidden

    ' Insert/remove a PageBreak only if this is NOT the first page
    If sPage <> msPAGE_1 Then

    If .EntireRow.Hidden = True And .Rows(1).Row > 1 Then
    .Rows(1).EntireRow.PageBreak = xlPageBreakNone
    Else: .Rows(1).EntireRow.PageBreak = xlPageBreakManual
    End If

    End If

    End With

    End Sub


    '=========================================================================================
    '=========================================================================================


    Private Sub PageBreakIsInserted(sPage As String, bTrueorFalse As Boolean)

    With ActiveSheet.Range(sPage).Rows(1)

    If bTrueorFalse = True Then
    .PageBreak = xlPageBreakManual
    Else: .PageBreak = xlPageBreakNone
    End If

    End With

    End Sub
    [code}

  10. #10
    Forum Expert Greg M's Avatar
    Join Date
    08-16-2007
    Location
    Dublin. Ireland
    MS-Off Ver
    Office 2016
    Posts
    4,481

    Re: Collapsed Section / Hidden page, prints as a blank page

    Hi again,

    Ok, see if the attached version of the workbook does what you need.


    It uses the following code in the VBA CodeModule of the worksheet in question:


    Please Login or Register  to view this content.

    and the following code in a standard VBA CodeModule:

    Please Login or Register  to view this content.
    The highlighted values may be altered to suit your requirements.


    Hope this helps - as before, please let me know how you get on.

    Regards,

    Greg M
    Attached Files Attached Files
    Last edited by Greg M; 10-29-2019 at 08:24 AM. Reason: Typo corrected

+ 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. Excel 2016 - Chart displays on screen but prints blank page
    By ahartman in forum Excel Charting & Pivots
    Replies: 1
    Last Post: 10-15-2016, 06:10 AM
  2. [SOLVED] Page Layout (Page Break Preview) is not working with hidden rows in excel.
    By ebin charles in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 05-31-2013, 03:32 AM
  3. [SOLVED] Having difficultly moving a section from page 3 to page 2 in a word document form
    By UNAB in forum Word Formatting & General
    Replies: 2
    Last Post: 03-25-2013, 07:52 AM
  4. Excel 2010 prints first extra blank page
    By kvharm in forum Excel General
    Replies: 2
    Last Post: 08-28-2012, 04:51 AM
  5. Include a separator page (blank) after a specified amount of prints
    By Papa28x4 in forum Word Programming / VBA / Macros
    Replies: 2
    Last Post: 07-01-2012, 08:27 AM
  6. First page prints normal, other pages print blank, why?
    By Cyberpawz in forum Word Formatting & General
    Replies: 4
    Last Post: 01-25-2012, 08:31 AM
  7. [SOLVED] When I'm trying to print a document, an extra blank page prints
    By Angie in forum Excel General
    Replies: 3
    Last Post: 08-15-2006, 03:50 PM

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