hello everyone

I have a document which I need to break into sections(nextPage).
Im doing a search for 3 asterix marks and when found, insert the
sectionbreak.
I need to run the code until the end of document only once everytime it is
run.
Do I have to delete the existing section breaks first.

heres the code I have so far. It keeps looping nonstop

Sub letsDivide()
Selection.HomeKey wdStory
Selection.Find.ClearFormatting
Selection.Find.Replacement.ClearFormatting
With Selection.Find
Do While .Execute(FindText:="***", Forward:=True, Wrap:=wdFindContinue,
MatchWildcards:=False _
) = True
Loop
End With
Selection.InsertBreak Type:=wdSectionBreakNextPage
End Sub
Any help will be appreciated.

thanx
ahmed

Re: nextPage sectionBreak by Helmut

Helmut
Tue Sep 11 11:09:32 CDT 2007

Hi FotoArt,

if you search for a string
and the string is found,
and you do nothing to what is then the selection,
then the selection stays the found range,
and your search finds the string again.

Thats the way I'do it:

Sub LetsDivideA()
Dim rDcm As Range
Set rDcm = ActiveDocument.Range
With rDcm.Find
.Text = "***"
While .Execute
rDcm.InsertBreak Type:=wdSectionBreakNextPage
rDcm.Start = rDcm.End + 1 '!
rDcm.End = ActiveDocument.Range.End '!
Wend
End With
End Sub

Pay special attention to the part of the code,
which redefines rDcm.

--
Greetings from Bavaria, Germany

Helmut Weber, MVP WordVBA

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

Re: nextPage sectionBreak by FotoArt

FotoArt
Tue Sep 25 13:06:00 CDT 2007

hello weber
How could I insert the section break after the asterics.
What happens now is the break comes before the "***"
thanx
ahmed

"Helmut Weber" wrote:

> Hi FotoArt,
>
> if you search for a string
> and the string is found,
> and you do nothing to what is then the selection,
> then the selection stays the found range,
> and your search finds the string again.
>
> Thats the way I'do it:
>
> Sub LetsDivideA()
> Dim rDcm As Range
> Set rDcm = ActiveDocument.Range
> With rDcm.Find
> .Text = "***"
> While .Execute
> rDcm.InsertBreak Type:=wdSectionBreakNextPage
> rDcm.Start = rDcm.End + 1 '!
> rDcm.End = ActiveDocument.Range.End '!
> Wend
> End With
> End Sub
>
> Pay special attention to the part of the code,
> which redefines rDcm.
>
> --
> Greetings from Bavaria, Germany
>
> Helmut Weber, MVP WordVBA
>
> Win XP, Office 2003
> "red.sys" & Chr$(64) & "t-online.de"
>

Re: nextPage sectionBreak by Helmut

Helmut
Tue Sep 25 13:29:54 CDT 2007

Hi Ahmed,

like that:

Sub LetsDivideAA()
Dim rDcm As Range
Set rDcm = ActiveDocument.Range
With rDcm.Find
.Text = "***" & Chr(12)
While .Execute
rDcm.Select ' for testing using single step mode
rDcm.Characters.Last = ""
rDcm.Collapse direction:=wdCollapseEnd
rDcm.Select ' for testing using single step mode
rDcm.InsertBreak Type:=wdSectionBreakNextPage
rDcm.Collapse direction:=wdCollapseEnd
rDcm.Select ' for testing using single step mode
Wend
End With
End Sub

Which works, beware, on every chr(12) preceded by 3 asteriscs,
no matter, what kind of break it is.

For learning about the whole truth about chr(12), see:

KindOfBreak12
http://tinyurl.com/ynwgnv


--
Greetings from Bavaria, Germany

Helmut Weber, MVP WordVBA

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