VBA Code to remove/replace section breaks

R

roseg

I'm trying to create a macro that will go through a Word document and
remove continuous section breaks and change all section break next page
to page breaks. I am a little at a loss. Can someone give me some
direction?

TIA

Rose
 
H

Helmut Weber

Hi Rose,

see:

http://tinyurl.com/y72lf2

which is far from perfect.
If I had to do it again,
I would avoid the selection-object.


--
Greetings from Bavaria, Germany

Helmut Weber, MVP WordVBA

Win XP, Office 2003
"red.sys" & Chr$(64) & "t-online.de"
 
H

Helmut Weber

Hi,

somewhat revised an updated,
Excluding columnbreak, which is chr(14),
and text wrapping break, which is chr(11).

Sub Test012X()
Dim lBrk As Long ' kind of break
Dim rDcm As Range ' the documents range
Set rDcm = ActiveDocument.Range
With rDcm.Find
.Text = Chr(12)
While .Execute
rDcm.Select ' for testing, remove later
Stop ' for testing, remove later
lBrk = KindofBreak12(rDcm)
Select Case lBrk
Case 0:
rDcm.Characters.Last.Previous = ""
Case 2, 3, 4:
rDcm.Characters.Last.Previous.InsertBreak _
Type:=wdPageBreak
End Select
rDcm.Collapse Direction:=wdCollapseEnd
Wend
End With

End Sub

Public Function KindofBreak12(ByVal rTmp As Range) As Long
Dim lSct1 As Long ' counter for sections
Dim lSct2 As Long ' counter for sections
rTmp.start = ActiveDocument.Range.start
lSct1 = rTmp.Sections.Count ' count sections
rTmp.End = rTmp.End + 1 ' extend range
lSct2 = rTmp.Sections.Count ' count sections again
If lSct1 = lSct2 Then ' next caracter is in the same section
KindofBreak12 = -1 ' ordinary pagebreak
Else
KindofBreak12 =
ActiveDocument.Sections(lSct2).PageSetup.SectionStart
End If

'wdSectionContinuous ' 0
'wdSectionNewPage ' 2
'wdSectionEvenPage ' 3
'wdSectionOddPage '4

End Function


HTH


--
Greetings from Bavaria, Germany

Helmut Weber, MVP WordVBA

Win XP, Office 2003
"red.sys" & Chr$(64) & "t-online.de"
 

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