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?
"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