SOLVED: Remove section breaks from document

Robie
5StarLounger
Posts: 656
Joined: 18 Feb 2010, 14:26

SOLVED: Remove section breaks from document

Post by Robie »

Hi

I know this should be simple but when I use Find & Replace on my documents to replace section breaks (^b), it *doesn't* remove 'Even Page Section break'! :(. It removes other 'next page section breaks'.

BTW: I am hoping run this as a macro in my template.

Thanks.
Robie
Last edited by Robie on 03 Jun 2015, 09:55, edited 1 time in total.

User avatar
Rudi
gamma jay
Posts: 25455
Joined: 17 Mar 2010, 17:33
Location: Cape Town

Re: Remove section breaks from document

Post by Rudi »

I am using Office 2013 and this code will remove all breaks.
Tested on a doc with various breaks and all got removed.

You can modify it to determine which breaks to replace....

Code: Select all

Sub Delete_all_breaks_from_selection()
Dim arr() As Variant
Dim i As Byte
Selection.Find.ClearFormatting
Selection.Find.Replacement.ClearFormatting
'"^b" - Selection Breaks, "^m" - Page Break, "^n" - Column Break
arr = Array("^b", "^m", "^n")
    For i = LBound(arr) To UBound(arr)
        With Selection.Find
            .Text = arr(i)
            .Replacement.Text = ""
        End With
    Selection.Find.Execute Replace:=wdReplaceAll
    Next
End Sub
Regards,
Rudi

If your absence does not affect them, your presence didn't matter.

Robie
5StarLounger
Posts: 656
Joined: 18 Feb 2010, 14:26

Re: Remove section breaks from document

Post by Robie »

Rudi wrote:I am using Office 2013 and this code will remove all breaks.
Tested on a doc with various breaks and all got removed.

You can modify it to determine which breaks to replace....

Code: Select all

Sub Delete_all_breaks_from_selection()
Dim arr() As Variant
Dim i As Byte
Selection.Find.ClearFormatting
Selection.Find.Replacement.ClearFormatting
'"^b" - Selection Breaks, "^m" - Page Break, "^n" - Column Break
arr = Array("^b", "^m", "^n")
    For i = LBound(arr) To UBound(arr)
        With Selection.Find
            .Text = arr(i)
            .Replacement.Text = ""
        End With
    Selection.Find.Execute Replace:=wdReplaceAll
    Next
End Sub
Thanks Rudi but that *doesn't* remove the 'Even Page Section Break' :(. It removes the 'Next Page Section Breaks' fine - no problems.

Update: If I just use the Ctrl-F searching for '^b', it find the two section breaks (next page and even page) but if I then change find to replace, it only replaces the next page section break - not the even page (even though it finds it). Even if I keep trying to replace several times, it fails all the time. :( Alos, the even section break is the last section break in the document.

User avatar
Rudi
gamma jay
Posts: 25455
Joined: 17 Mar 2010, 17:33
Location: Cape Town

Re: Remove section breaks from document

Post by Rudi »

Does your document have protection in that part (or section)?
Do you have track changes active?
Is the section break attached to a style in the document?
Regards,
Rudi

If your absence does not affect them, your presence didn't matter.

Robie
5StarLounger
Posts: 656
Joined: 18 Feb 2010, 14:26

SOLVED: Remove section breaks from document

Post by Robie »

Found a solution. :)

Now, I just search and delete manually rather than using "Selection.Find.Execute Replace:=wdReplaceAll" I do as follows:

Code: Select all

        While (Selection.Find.Execute)
            Selection.Delete
        Wend
Thanks for taking time out to read my post.
Robie

Robie
5StarLounger
Posts: 656
Joined: 18 Feb 2010, 14:26

Re: Remove section breaks from document

Post by Robie »

Rudi wrote:Does your document have protection in that part (or section)?
Do you have track changes active?
Is the section break attached to a style in the document?
Hi Rudi

None of the above are true but as you can see I have now managed to solve my problem.
Thanks for thinking about it.

User avatar
Rudi
gamma jay
Posts: 25455
Joined: 17 Mar 2010, 17:33
Location: Cape Town

Re: SOLVED: Remove section breaks from document

Post by Rudi »

Cheers
TX for the feedback!
Regards,
Rudi

If your absence does not affect them, your presence didn't matter.