Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Word / Programming / September 2007

Tip: Looking for answers? Try searching our database.

nextPage sectionBreak

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
FotoArt - 11 Sep 2007 16:44 GMT
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
Helmut Weber - 11 Sep 2007 17:09 GMT
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.

Signature

Greetings from Bavaria, Germany

Helmut Weber, MVP WordVBA

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

FotoArt - 25 Sep 2007 19:06 GMT
hello weber
How could I insert the section break after the asterics.
What happens now is the break comes before the "***"
thanx
ahmed

> Hi FotoArt,
>
[quoted text clipped - 21 lines]
> Pay special attention to the part of the code,
> which redefines rDcm.
Helmut Weber - 25 Sep 2007 19:29 GMT
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

Signature

Greetings from Bavaria, Germany

Helmut Weber, MVP WordVBA

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


Rate this thread:






 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.