Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 07-13-2011, 09:09 PM
Aston Aston is offline Delete a page after Section Break Next Page Windows XP Delete a page after Section Break Next Page Office 2007
Novice
Delete a page after Section Break Next Page
 
Join Date: May 2011
Posts: 15
Aston is on a distinguished road
Default Delete a page after Section Break Next Page

Hello everyone,

Working closely with Word for almost a year as an editor, I've gotten used to the fact that it likes to pull pranks on you. And sometimes you have to conduct some crazy manipulations to do some simple things.

I wonder if deleting a page after a Section Break Next Page is an example of that.

I know that the page that follows is the result of the type of the Section Break, which in this case is "Next Page", so Word automatically adds a new page after it. I have to delete the Section Break Next Page first, but it controls to many formatting elements (the page has a different header and footer and page orientation), so deleting it results in losing all that formatting.



Is it possible to delete the page after Section Break Next Page painlessly?

I attached an example file just in case. (I use Word 2007)

Thank you very much for your help.
Attached Files
File Type: docx PageThreeToBeDeleted.docx (21.9 KB, 24 views)
Reply With Quote
  #2  
Old 07-14-2011, 09:22 AM
Ulodesk Ulodesk is offline Delete a page after Section Break Next Page Windows 7 32bit Delete a page after Section Break Next Page Office 2007
Word 2013 Expert Cert
 
Join Date: Sep 2009
Location: Virginia
Posts: 866
Ulodesk is on a distinguished road
Default

Hi, Aston. As long as you don't intend to have any pages follow your landscape page, you can delete the next-page section break on it, i.e., your second section break. The trick is, you must first change the page orientation of page three to landscape.

Best,
Ulodesk
Reply With Quote
  #3  
Old 07-14-2011, 02:41 PM
Aston Aston is offline Delete a page after Section Break Next Page Windows XP Delete a page after Section Break Next Page Office 2007
Novice
Delete a page after Section Break Next Page
 
Join Date: May 2011
Posts: 15
Aston is on a distinguished road
Default

Thanks for your reply, Ulodesk.

But it only solves half of the problem.

As I mentioned (and as you can see in my example file attached), the page that needs to be deleted has a different header and footer. When you delete Section Break Next Page on the previous page, it "inherits" the footer and header of the deleted page.

So before deleting the page I do not need, I have to change its orientation, then make sure my headers and footers are the same on both pages, and what if I also have a multiple column layout on the previous page, I have to set up the same layout on the to-be-deleted page as well. Because I know that all this formatting will be gone once I remove the Section Break.

Don't you think it's just too much hustle for a page that's going to be deleted anyway?

Regards,
Aston
Reply With Quote
  #4  
Old 07-14-2011, 03:41 PM
macropod's Avatar
macropod macropod is offline Delete a page after Section Break Next Page Windows 7 64bit Delete a page after Section Break Next Page Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,962
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

Hi Aston,

Before deleting the unwanted Section, you need to format it the same as the preceding Section, including header & footer content.

If the unwanted page is created knowing its "a page that's going to be deleted anyway", why are you creating it in the first place?
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #5  
Old 07-14-2011, 04:50 PM
Aston Aston is offline Delete a page after Section Break Next Page Windows XP Delete a page after Section Break Next Page Office 2007
Novice
Delete a page after Section Break Next Page
 
Join Date: May 2011
Posts: 15
Aston is on a distinguished road
Default

Quote:
Originally Posted by macropod View Post
If the unwanted page is created knowing its "a page that's going to be deleted anyway", why are you creating it in the first place?
Because I edit other people's documents as my job. And some documents are really screwed up. Sometimes they put section breaks on every page. I guess they mix them up with page breaks. Really annoying.

Last edited by Charles Kenyon; 10-26-2018 at 06:40 AM.
Reply With Quote
  #6  
Old 07-14-2011, 05:43 PM
macropod's Avatar
macropod macropod is offline Delete a page after Section Break Next Page Windows 7 64bit Delete a page after Section Break Next Page Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,962
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

Hi Aston,

You could use a macro to expedite the process. Here's one to take care of the most common issues.
To use it, simply select a range that spans however many Section breaks need to be deleted for the Sections you want to merge. For example, if you want to merge two consecutive Sections, simply select a range spanning the offending Section break. For three Sections, select a range spanning both offending Section breaks.
Code:
Sub MergeSections()
Application.ScreenUpdating = False
Dim sPageHght As Single, sPageWdth As Single
Dim sHeaderDist As Single, sFooterDist As Single
Dim sTMargin As Single, sBMargin As Single
Dim sLMargin As Single, sRMargin As Single
Dim sGutter As Single, sGutterPos As Single
Dim lPaperSize As Long, lGutterStyle As Long
Dim lMirrorMargins As Long, lVerticalAlignment As Long
Dim lScnStart As Long, lScnDir As Long
Dim lOddEvenHdFt As Long, lDiffFirstHdFt As Long
Dim bTwoPagesOnOne As Boolean, bBkFldPrnt As Boolean
Dim bBkFldPrnShts As Boolean, bBkFldRevPrnt As Boolean
Dim bOrientation As Boolean, oHdFt As HeaderFooter
Dim Sctn1 As Section, Sctn2 As Section
With Selection
  If .Sections.Count = 1 Then
    MsgBox "Selection does not span a Section break", vbExclamation
    Exit Sub
  End If
  Set Sctn1 = .Sections.First: Set Sctn2 = .Sections.Last
  With Sctn1.PageSetup
    lPaperSize = .PaperSize
    lGutterStyle = .GutterStyle
    bOrientation = .Orientation
    lMirrorMargins = .MirrorMargins
    lScnStart = .SectionStart
    lScnDir = .SectionDirection
    lOddEvenHdFt = .OddAndEvenPagesHeaderFooter
    lDiffFirstHdFt = .DifferentFirstPageHeaderFooter
    lVerticalAlignment = .VerticalAlignment
    sPageHght = .PageHeight
    sPageWdth = .PageWidth
    sTMargin = .TopMargin
    sBMargin = .BottomMargin
    sLMargin = .LeftMargin
    sRMargin = .RightMargin
    sGutter = .Gutter
    sGutterPos = .GutterPos
    sHeaderDist = .HeaderDistance
    sFooterDist = .FooterDistance
    bTwoPagesOnOne = .TwoPagesOnOne
    bBkFldPrnt = .BookFoldPrinting
    bBkFldPrnShts = .BookFoldPrintingSheets
    bBkFldRevPrnt = .BookFoldRevPrinting
  End With
  With Sctn2.PageSetup
    .GutterStyle = lGutterStyle
    .MirrorMargins = lMirrorMargins
    .SectionStart = lScnStart
    .SectionDirection = lScnDir
    .OddAndEvenPagesHeaderFooter = lOddEvenHdFt
    .DifferentFirstPageHeaderFooter = lDiffFirstHdFt
    .VerticalAlignment = lVerticalAlignment
    .PageHeight = sPageHght
    .PageWidth = sPageWdth
    .TopMargin = sTMargin
    .BottomMargin = sBMargin
    .LeftMargin = sLMargin
    .RightMargin = sRMargin
    .Gutter = sGutter
    .GutterPos = sGutterPos
    .HeaderDistance = sHeaderDist
    .FooterDistance = sFooterDist
    .TwoPagesOnOne = bTwoPagesOnOne
    .BookFoldPrinting = bBkFldPrnt
    .BookFoldPrintingSheets = bBkFldPrnShts
    .BookFoldRevPrinting = bBkFldRevPrnt
    .PaperSize = lPaperSize
    .Orientation = bOrientation
  End With
  With Sctn2
    For Each oHdFt In .Footers
      oHdFt.LinkToPrevious = Sctn1.Footers(oHdFt.Index).LinkToPrevious
      If oHdFt.LinkToPrevious = False Then
        With oHdFt.Range
          .FormattedText = Sctn1.Footers(oHdFt.Index).Range.FormattedText
          Do While .Characters.Last.Previous = vbCr
            .Characters.Last.Previous.Delete
            If .Characters.Count = 1 Then Exit Do
          Loop
        End With
      End If
    Next
    For Each oHdFt In .Headers
      oHdFt.LinkToPrevious = Sctn1.Headers(oHdFt.Index).LinkToPrevious
      If oHdFt.LinkToPrevious = False Then
        With oHdFt.Range
          .FormattedText = Sctn1.Headers(oHdFt.Index).Range.FormattedText
          Do While .Characters.Last.Previous = vbCr
            .Characters.Last.Previous.Delete
            If .Characters.Count = 1 Then Exit Do
          Loop
        End With
      End If
    Next
  End With
  While .Sections.Count > 1
    .Sections.First.Range.Characters.Last.Delete
  Wend
End With
Set Sctn1 = Nothing: Set Sctn2 = Nothing
Application.ScreenUpdating = True
End Sub
For PC macro installation & usage instructions, see: http://www.gmayor.com/installing_macro.htm
For Mac macro installation & usage instructions, see: http://word.mvps.org/Mac/InstallMacro.html
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #7  
Old 04-26-2022, 03:44 PM
Astrid Astrid is offline Delete a page after Section Break Next Page Windows 10 Delete a page after Section Break Next Page Office 2019
Novice
 
Join Date: Apr 2022
Posts: 5
Astrid is on a distinguished road
Default Bookmarks in header

I know this is an old post. I stumbled across it looking for a solution with a random appearing error 4605 trying to set the linktoprevious property of a section.
Paul, your code works perfectly, thanks!

In my situation I need to delete the whole last section. With some modifications this works well too. One thing though, because of the use of .formattedtext I lose bookmarks that are used in the header of first section. Any idea on how to fix that?
Reply With Quote
  #8  
Old 04-26-2022, 05:16 PM
Astrid Astrid is offline Delete a page after Section Break Next Page Windows 10 Delete a page after Section Break Next Page Office 2019
Novice
 
Join Date: Apr 2022
Posts: 5
Astrid is on a distinguished road
Default

My mistake, it is not the formattedtext property, it is the deleting of the actual section break:

Code:
  While .Sections.Count > 1
    .Sections.First.Range.Characters.Last.Delete
  Wend
It is easy to reproduce:
1. Create a document with two sections
2. First section with different first page, in header first page add two bookmarks
3. Add second section, only primary headers/footers, both empty
4. Select last paragraph first section, and first second section
5. Run the code
6. Bookmarks in first section are gone

Is it possible to solve this?
Reply With Quote
  #9  
Old 04-27-2022, 06:28 AM
macropod's Avatar
macropod macropod is offline Delete a page after Section Break Next Page Windows 10 Delete a page after Section Break Next Page Office 2016
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,962
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

The bookmarks are deleted because the content they were attached to gets deleted. The workaround requires something like (untested) -

Change:
Code:
Dim Sctn1 As Section, Sctn2 As Section
to:
Code:
Dim Sctn1 As Section, Sctn2 As Section, BkMk As Bookmark, x As Long, y As Long
After:
Code:
          .FormattedText = Sctn1.Footers(oHdFt.Index).Range.FormattedText
insert:
Code:
          For Each BkMk In Sctn1.Footers(oHdFt.Index).Range
            x = BkMk.Range.Start: y = BkMk.Range.End
            .Bookmarks.Add Name:=BkMk.Name, Range:=.SetRange(x, y)
          Next
After:
Code:
          .FormattedText = Sctn1.Headers(oHdFt.Index).Range.FormattedText
insert:
Code:
          For Each BkMk In Sctn1.Headers(oHdFt.Index).Range
            x = BkMk.Range.Start: y = BkMk.Range.End
            .Bookmarks.Add Name:=BkMk.Name, Range:=.SetRange(x, y)
          Next
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #10  
Old 04-27-2022, 07:38 AM
Astrid Astrid is offline Delete a page after Section Break Next Page Windows 10 Delete a page after Section Break Next Page Office 2019
Novice
 
Join Date: Apr 2022
Posts: 5
Astrid is on a distinguished road
Default

Thanks Paul,

Just what I came up with myself ;-)
I created a subroutine that takes the two ranges as an argument and loops through all the bookmarks and recreates the bookmarks in the second range.
Thanks again for your assistance!
Reply With Quote
Reply



Similar Threads
Thread Thread Starter Forum Replies Last Post
why the "section break-next page" is switched to "section break-continuous"? Jamal NUMAN Word 6 12-14-2011 03:35 PM
Delete a page after Section Break Next Page Page break - next page Commodore Word 7 07-17-2011 12:09 AM
Delete a page after Section Break Next Page Section Break Continuous: doesn't affect the format of the page numbering Jamal NUMAN Word 2 06-22-2011 04:46 PM
Delete a page after Section Break Next Page Page numbering starting on 2 after section break pamm13 Word 1 06-22-2011 11:10 AM
Delete a page after Section Break Next Page Anchoring a section break to the bottom of a page, and having a table pass over it??? h3rk Word Tables 1 11-20-2009 07:34 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 04:00 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2024 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft