Sorry, No Word Macro Forum. Macro To Search And Copy All Occurances

Joined
Dec 17, 2007
Messages
3
Reaction score
0
This macro searches for the phrase "S E G - D" and then copies the next 20 lines. It is supposed to continue doing this until the end of the document, stringing all of the occurances together, and then paste them all into a new document. This macro only does the first occurance.

Code:
Sub CopyParas()
Application.ScreenUpdating = False
Selection.HomeKey Unit:=wdStory
Selection.Find.ClearFormatting
With Selection.Find
.Text = "S E G - D"
.Forward = True
.Wrap = wdFindStop
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Do While Selection.Find.Execute
Selection.StartOf Unit:=wdLine
Selection.MoveEnd Unit:=wdLine
Selection.MoveDown Unit:=wdLine, Count:=20, Extend:=wdExtend
sBigString = sBigString + Selection.Text
Selection.MoveStart Unit:=wdLine
Loop
Documents.Add DocumentType:=wdNewBlankDocument
Selection.InsertAfter (sBigString)
Application.ScreenUpdating = True
End Sub

other post link
http://www.ozgrid.com/forum/showthread.php?t=89720
 

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