remove all section breaks quickly?

G

Greg Maxey

Stephan,

Actually it needs a qualifier to keep from tripping up on a break found
outside a table:

Sub ScratchMacro()
Dim i As Long
Dim oRng As Range
Set oRng = ActiveDocument.Range
With oRng.Find
.Text = Chr(12)
While .Execute
oRng.Select
If oRng.Information(wdWithInTable) Then
oRng.MoveEnd wdCharacter, 1
oRng.Collapse wdCollapseStart
With Selection
.MoveRight Unit:=wdCharacter, Count:=1
.SplitTable
.MoveLeft Unit:=wdCharacter, Count:=1
.MoveRight Unit:=wdCharacter, Count:=1, Extend:=wdExtend
.Delete Unit:=wdCharacter, Count:=1
.Delete Unit:=wdCharacter, Count:=1
End With
Else
oRng.Delete
oRng.Collapse Direction:=wdCollapseEnd
End If
Wend
End With
End Sub
 
G

Greg Maxey

Stefan,

Actually on closer look it doesn't need to be so complicated at all. I can
only guess that using the selection is what makes it uncooperative. This
seems to work just fine for all section breaks (in or not in a table):

Sub ScratchMacro()
Dim oRgn As Range
Set oRgn = ActiveDocument.Range
With oRgn.Find
.Text = Chr(12)
While .Execute
oRgn.Delete
oRgn.Collapse Direction:=wdCollapseEnd
Wend
End With
End Sub
 
M

mcarpeneto

Thanks, Greg
Your code worked for me.

Greg Maxey said:
Stefan,

Actually on closer look it doesn't need to be so complicated at all. I can
only guess that using the selection is what makes it uncooperative. This
seems to work just fine for all section breaks (in or not in a table):

Sub ScratchMacro()
Dim oRgn As Range
Set oRgn = ActiveDocument.Range
With oRgn.Find
.Text = Chr(12)
While .Execute
oRgn.Delete
oRgn.Collapse Direction:=wdCollapseEnd
Wend
End With
End Sub
 
L

lflea

TEAM NORTON said:
I copied an Adobe document into Word and now the section breaks are all over
the place leaving me with very ragged and rambling text. I can delete the
section breaks one at a time but there are thousands. Can I delete them all
(without deleting the text - done that already!), or align the text? Thanks.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top