Good day folks,
I am attempting to extract some words from my document into another one
I have got stuck on the words range idea
I have listed my words in an array
I want to extract the word plus 2 words before and 1 word after
And i have researched and tried all sorts
End result would be
the blue car is
nice blue car toyota
A blue train which
Expensive great trains are
Dim i As Long, oWords, RngSrc As Range, RngTgt As Range,
dim DocSrc As Document, Tgt As Document
oWords= Array("Car", "Train")
Set DocSrc = ActiveDocument
For i = 0 To UBound(oWords)
Set DocTgt = Documents.Add
With DocSrc.Range
With .Find
.ClearFormatting
.Replacement.ClearFormatting
.Text = oWords(i)
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindStop
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
.Execute
End With
Do While .Find.Found
Set RngSrc = .Text(1).Range
' having some trouble here
'Selection.MoveLeft Unit:=wdWord, Count:=2, Extend:=wdExtend
Set RngTgt = oTgt.Range.Characters.Last
RngTgt.Collapse wdCollapseStart
RngTgt.FormattedText = RngSrc.FormattedText
.Start = RngSrc.End
.Find.Execute
Loop
End With
please do add some kindly eyes on this mishmash code
thank you