|
|
|
date: Sat, 5 Apr 2008 14:01:04 -0500,
group: microsoft.public.word.vba.beginners
back
Re: Replace Page Breaks with Section Break-Next Page
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
"Farrar > Tweety" wrote in message
news:iPudnSDEufHtlGXanZ2dnUVZ_sqinZ2d@sunflowerdatavision...
> 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-
>
> "Doug Robbins - Word MVP" wrote in message
> news:uUiJ0g2lIHA.536@TK2MSFTNGP06.phx.gbl...
>> 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
>>
>> "Sandusky" wrote in message
>> news:C7CdnTHEo89HV2ranZ2dnUVZ_qmlnZ2d@sunflowerdatavision...
>>> Windows XP Pro SP2
>>> Word 2003 SP3
>>>
>>> Can this be done with a Macro for the entire document?
>>>
>>> Thanks!
>>>
>>> -gk-
>>>
>>
>>
>
>
date: Sun, 6 Apr 2008 10:45:14 +1000
author: Doug Robbins - Word MVP
|
|