Ureader.com  
Microsoft software help and Community
   home   |   control panel login   |   archive   |  
 
Word
application.errors
conversions
docmanagement
drawing.graphics
formatting.longdocs
international
internet.assistant
mail
mailmerge.fields
menustoolbars
newusers
numbering
oleinterop
pagelayout
printingfonts
setup.networking
spelling.grammar
tables
vba.addins
vba.beginners
vba.customization
vba.general
vba.userforms
web.authoring
word6-7macros
word97vba
  
 
date: Sat, 10 Mar 2007 16:17:05 -0800,    group: microsoft.public.word.vba.customization        back       


End of section in Do Until ... Loop   
I am using Word in Office 2003. I am trying to write a Do Until ... Loop that 
will search for a specific part of the text, make a selection and add coding 
and do it only until the section break. The loop either doesn't work or the 
macro freezes. 
If I wanted to go to the end of the document, I could use something like:
Do Until ActiveDocument.Bookmarks("\Sel") = 
ActiveDocument.Bookmarks("\EndOfDoc")
Is there a similar statement that will run only until the section break?
date: Sat, 10 Mar 2007 16:17:05 -0800   author:   tgsysed

Re: End of section in Do Until ... Loop   
"tgsysed" wrote:
>I am using Word in Office 2003. I am trying to write a Do Until ... Loop 
>that
> will search for a specific part of the text, make a selection and add 
> coding
> and do it only until the section break. The loop either doesn't work or 
> the
> macro freezes.
> If I wanted to go to the end of the document, I could use something like:
> Do Until ActiveDocument.Bookmarks("\Sel") =
> ActiveDocument.Bookmarks("\EndOfDoc")
> Is there a similar statement that will run only until the section break?

There's a built-in bookmark \Section, but this is usually approached 
differently.

You could set some range to the current section's range:
  Set rngSection = Selection.Sections(1).Range

Then use some other Range, say rngFind, which you are going to search:

  Set rngFind = rngSection.Duplicate

Now you can do your Find loop:

  With rngFind.Find
     ' set up your Find or Replacement
     .Text = "text to find"
     ' ...
     .Wrap = wdFindStop
     ' ...
  End With
  Do While rngFind.Find.Execute
      ' add coding (whatever that means)
      ' your code ...
      ' rngFind is now still set to the current match.
      ' You need to set rngFind so it covers the rest of rngSection:
      rngFind.Collapse(wdCollapseEnd)
      rngFind.End=rngSection.End
 Loop

If nothing is found in the remainder of the section, .Execute will evaluate 
to "False", and "Do ... Loop" will stop (because .Wrap is set 
appropriately).

Regards,
Klaus
date: Sun, 11 Mar 2007 03:40:22 +0100   author:   Klaus Linke

Google
 
Web ureader.com


    COPYRIGHT 2007, YARDI TECHNOLOGY LIMITED, ALL RIGHT RESERVE  |   contact us