Replace Page Breaks with Section Break-Next Page

S

Sandusky

Windows XP Pro SP2
Word 2003 SP3

Can this be done with a Macro for the entire document?

Thanks!

-gk-
 
D

Doug Robbins - Word MVP

The following code should create a new document containing each page from
the source document separated by a next page section break.

Dim Counter As Long, Pages As Long
Dim Source As Document, Target As Document
Dim trange As Range
Set Source = ActiveDocument
Selection.HomeKey Unit:=wdStory
Pages = Source.BuiltInDocumentProperties(wdPropertyPages)
Counter = 0
Set Target = Documents.Add
While Counter < Pages
Counter = Counter + 1
Source.Bookmarks("\Page").Range.Cut
With Target
Set trange = .Range
trange.Collapse wdcollapse.End
trange.Paste
Set trange = .Range
trange.Collapse wdcollapse.End
trange.InsertBreak wdSectionBreakNextPage
End With
Wend


--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP
 
F

Farrar > Tweety

Thanks Doug.

That's close, but not quite what I need.

I have a document that is already formatted close to what I want. There are
45 chapters in the document, and each chapter has a Page Break after it.
Each chapter has formatting that is consistent from chapter to chapter. My
experience has taught me that section breaks are easier to loop through,
especially in this case. So I was hoping to just replace/substitute the
Page Breaks with a Section Break - Next Page.

-gk-
 
D

Doug Robbins - Word MVP

Try

Dim myrange1 As Range, myrangedup As Range
Selection.HomeKey wdStory
Selection.Find.ClearFormatting
With Selection.Find
Do While .Execute(findText:="^m", Forward:=True, _
MatchWildcards:=False, Wrap:=wdFindStop) = True
Set myrange = Selection.Range
Set myrangedup = Selection.Range.Duplicate
myrange.Collapse wdCollapseEnd
myrange.InsertBreak wdSectionBreakNextPage
myrangedup.Delete
Loop
End With


--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP
 

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