vba replace for improper page breaks in Word 2003

R

Rich Lawson

We are receiving thousands of documents which need to be reformated for page
breaks and section break.

These are batch files containing hundreds of documents which end with a Page
Break followed by a Section Break(Continuous).

To process these files, the Page Break/Section Break(Continuous) needs to be
replaced with a Section Break(Next Page).

Using vba and Word 2003 we have been able to do simple search and replace of
the Page Break OR the Section Break(Continuous) but not the Page Break AND
the Section Break(Continuous).

Also, I can find no code for doing a Replace on the Section Break(Next
Page).

Rich Lawson
Applications Developer
AAM, LLC
 
D

Doug Robbins - Word MVP

Use:

Dim i As Long
With ActiveDocument
For i = 2 To .Sections.Count
.Sections(i).PageSetup.SectionStart = wdSectionNewPage
Next i
End With
Selection.HomeKey wdStory
Selection.Find.ClearFormatting
With Selection.Find
Do While .Execute(FindText:="^m^b", Forward:=True, _
MatchWildcards:=False, _
Wrap:=wdFindContinue, MatchCase:=False) = True
Selection.Collapse wdCollapseStart
Selection.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, originally posted via msnews.microsoft.com
 
R

Rich Lawson

Thank you. That works perfectly. I was close. I am glad I spent the time
trying to solve it.

Rich Lawson
 

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