replace manual page breaks

T

tjtjjtjt

Is it possible to programmatically replace all manual page breaks in a
document with Next Page Section Breaks?
Thanks.
 
J

Jean-Guy Marcil

tjtjjtjt was telling us:
tjtjjtjt nous racontait que :
Is it possible to programmatically replace all manual page breaks in a
document with Next Page Section Breaks?
Thanks.

Try:

With ActiveDocument.Range.Find
.ClearFormatting
.Text = "^m"
Do While .Execute
With .Parent
.Delete
.InsertBreak wdSectionBreakNextPage
End With
Loop
End With


But watch out! Adding section breaks can mess up your headers/footers/page
numbering/etc..

--
Salut!
_______________________________________
Jean-Guy Marcil - Word MVP
(e-mail address removed)
Word MVP site: http://www.word.mvps.org
 
H

Helmut Weber

Hi,
Is it possible to programmatically replace all manual page breaks in a
document with Next Page Section Breaks?

programmatically there are no manual page breaks.
There are breaks of certain types:
'wdSectionContinuous ' 0
'wdSectionNewColumn ' 1
'wdSectionNewPage ' 2
'wdSectionEvenPage ' 3
'wdSectionOddPage '4


Maybe you can adapt the following,
otherwise ask again.

Sub test012()
Dim rDcm As Range ' the documents range
Set rDcm = ActiveDocument.Range
With rDcm.Find
.Text = Chr(12)
While .Execute
rDcm.Select ' for testing using [F8]
MsgBox KindofBreak12(rDcm)
' rDcm.Collapse Direction:=wdCollapseEnd
' might be necessary together with replace
Wend
End With
End Sub


Public Function KindofBreak12(ByVal rTmp As Range) As String
Dim lSct1 As Long ' counter for sections
Dim lSct2 As Long ' counter for sections
Dim lKoSc As Long ' kind of section.pagesetup.sectionstart
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 = "ordinary page break"
Exit Function
End If
' next character is in the next section
lKoSc = ActiveDocument.Sections(lSct2).PageSetup.SectionStart
Select Case lKoSc
Case 0: KindofBreak12 = "wdSectionContinuous"
Case 2: KindofBreak12 = "wdSectionNewPage"
Case 3: KindofBreak12 = "wdSectionEvenPage"
Case 4: KindofBreak12 = "wdSectionOddPage"
End Select
End Function

see in addition:

http://tinyurl.com/hkrxd

--
Greetings from Bavaria, Germany

Helmut Weber, MVP WordVBA

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

Helmut Weber

Hi Jean-Guy,

i'm ashamed, i was on the completely wrong track,
being so obsessed with section breaks.

--
Greetings from Bavaria, Germany

Helmut Weber, MVP WordVBA

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

Jean-Guy Marcil

Helmut Weber was telling us:
Helmut Weber nous racontait que :
Hi Jean-Guy,

i'm ashamed, i was on the completely wrong track,
being so obsessed with section breaks.

LOL

Not really, no need to be ashamed, you were just doing some lateral
thinking!

--
Salut!
_______________________________________
Jean-Guy Marcil - Word MVP
(e-mail address removed)
Word MVP site: http://www.word.mvps.org
 
T

tjtjjtjt

Thanks. That does it!

Actually, I'm want the Section Breaks to preapre the document for Headers
and Footers (which I didn't originally plan to use...and wouldn't if it was
up to me). I was a bit distressed to find that there was no option to use the
Replace feature to switch Page Breaks for Section Breaks.

Now, I'm going to (hopefully) use this code as part of a bigger routine that
will take the first paragraph of Heading 2 text in each section and make that
part of the Header, along with page numbering that starts at one for each
Section.

tj
 
R

Russ

Tjtjjtjt,
Thanks. That does it!

Actually, I'm want the Section Breaks to preapre the document for Headers
and Footers (which I didn't originally plan to use...and wouldn't if it was
up to me). I was a bit distressed to find that there was no option to use the
Replace feature to switch Page Breaks for Section Breaks.

Now, I'm going to (hopefully) use this code as part of a bigger routine that
will take the first paragraph of Heading 2 text in each section and make that
part of the Header,

You know how dictionaries can show the first and last definition on a page
header?

Check out this information on styleref fields used in headers in Word:
http://tinyurl.com/kcn4x
 
T

Tony Jollans

I was a bit distressed to find that there was no option to use the
Replace feature to switch Page Breaks for Section Breaks.

You can do it using F&R ...

Add a section break to your document, select it and copy it, delete it, and
then Replace All ^m with ^c.

The disadvantage - which may not affect you very much - is that it copies in
section formatting from the section you first created rather than inheriting
from where the break is.
will take the first paragraph of Heading 2 text in each section and make that
part of the Header

Take a look at StyleRef Fields for this
along with page numbering that starts at one for each
Section.

Having replaced Page Breaks with Section Breaks are you not going to have a
lot of Page 1s?
 
T

tjtjjtjt

Word 2003 does not seem to let me select a Section Break and Copy it into the
Replace with box. If I try with the keyboard, it only selects the Paragraph
mark on the same line with the Section Break and/or any text on that line.
Perhaps I'm missing a step, but I don't see what that could be.

Using ^c in the Replace with box puts ^c in the document instead of a
Section Break.
 
T

Tony Jollans

Perhaps I should have been more explicit. Copy the section break but do not
paste it anywhere; ^c uses the contents of the clipboard for the
replacement.
 

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