adding a loop in a macro

R

russelworker

I need to find all the text for each "LVL" and move it to a new document. that is easy enough, but I cannot figure how to repeat the process, I think I need a loop.
help!

Sub find2(

' find2 Macr
' Macro recorded 4/22/2004 by arbuckle

Selection.FIND.ClearFormattin
With Selection.FIN
.Text = "lvl
.Replacement.Text = "
.Forward = Tru
.Wrap = wdFindContinu
.Format = Fals
.MatchCase = Fals
.MatchWholeWord = Fals
.MatchWildcards = Fals
.MatchSoundsLike = Fals
.MatchAllWordForms = Fals
End Wit
Selection.FIND.Execut
Selection.MoveLeft Unit:=wdCharacter, Count:=
Selection.MoveUp Unit:=wdLine, Count:=
Selection.MoveDown Unit:=wdLine, Count:=15, Extend:=wdExten
Selection.Cu
Windows("Document3").Activat
Selection.Past
Windows("DEV444.TXT").Activat

End Su

russelworker
 
D

Doug Robbins - Word MVP

Hi russelworker,

Are the 15 lines of text that you are selecting a single paragraph or a set
number of paragraphs? It will make it easier if it is.

However, the following will probably do what you want:

Dim myrange As Range, Source As Document, Target As Document
Set Source = ActiveDocument
Set Target = Documents.Add
Source.Activate
Selection.HomeKey Unit:=wdStory
Selection.Find.ClearFormatting
With Selection.Find
Do While .Execute(findText:="lvl", _
MatchCase:=False, MatchWildcards:=False, MatchWholeWord:=False,
Wrap:=wdFindContinue, Forward:=True) = True
Selection.MoveLeft Unit:=wdCharacter, Count:=1
Selection.MoveUp Unit:=wdLine, Count:=4
Selection.MoveDown Unit:=wdLine, Count:=15, Extend:=wdExtend
Set myrange = Selection.Range
Target.Range.InsertAfter myrange & vbCr
Loop
End With

--
Please post any further questions or followup to the newsgroups for the
benefit of others who may be interested. Unsolicited questions forwarded
directly to me will only be answered on a paid consulting basis.

Hope this helps
Doug Robbins - Word MVP
russelworker said:
I need to find all the text for each "LVL" and move it to a new document.
that is easy enough, but I cannot figure how to repeat the process, I think
I need a loop.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top