Creating a toggle control for Page Break

ABabeNChrist
SilverLounger
Posts: 1868
Joined: 25 Jan 2010, 14:00
Location: Conroe, Texas

Creating a toggle control for Page Break

Post by ABabeNChrist »

I’m trying to come up with a simple and user friendly approach that will help the user to set up page breaks before printing. I thought maybe I could use a toggle button on my Customize Quick Access Toolbar that will open and close page break.
I recorded this to open

Code: Select all

      ActiveWindow.View = xlPageBreakPreview
And this to Close

Code: Select all

    ActiveWindow.View = xlNormalView 
I’m just not sure how to put them together

User avatar
HansV
Administrator
Posts: 78370
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: Creating a toggle control for Page Break

Post by HansV »

Try this:

Code: Select all

Sub ToggleView()
  With ActiveWindow
    If .View = xlPageBreakPreview Then
      .View = xlNormalView
    Else
      .View = xlPageBreakPreview
    End If
  End With
End Sub
Best wishes,
Hans

ABabeNChrist
SilverLounger
Posts: 1868
Joined: 25 Jan 2010, 14:00
Location: Conroe, Texas

Re: Creating a toggle control for Page Break

Post by ABabeNChrist »

Thank you HansV
It works Perfecto

ABabeNChrist
SilverLounger
Posts: 1868
Joined: 25 Jan 2010, 14:00
Location: Conroe, Texas

Re: Creating a toggle control for Page Break

Post by ABabeNChrist »

Hi HansV
I tried to use the same approach with Print Preview as with Page Break
I know I’m close. I tried

Code: Select all

With ActiveWindow
If .SelectedSheets.PrintPreview Then
    .View = xlNormalView
    Else
    .SelectedSheets.PrintPreview
    End If
  End With

User avatar
HansV
Administrator
Posts: 78370
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: Creating a toggle control for Page Break

Post by HansV »

Code won't work in print preview, so you can't do this.
Best wishes,
Hans

ABabeNChrist
SilverLounger
Posts: 1868
Joined: 25 Jan 2010, 14:00
Location: Conroe, Texas

Re: Creating a toggle control for Page Break

Post by ABabeNChrist »

Hi HansV
I see what you mean
I think I will just use

Code: Select all

    ActiveWindow.SelectedSheets.PrintPreview
To open Print Preview and then return to active sheet by just closing from Print Preview close button, simple enought
Thank You

User avatar
HansV
Administrator
Posts: 78370
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: Creating a toggle control for Page Break

Post by HansV »

The user can also press the Esc key to close print preview.
Best wishes,
Hans

ABabeNChrist
SilverLounger
Posts: 1868
Joined: 25 Jan 2010, 14:00
Location: Conroe, Texas

Re: Creating a toggle control for Page Break

Post by ABabeNChrist »

Thank you HansV
I’m planning on creating a simple instructional manual for the use of this workbook / report and the easier I can make it for the user the better.
Thanks again