D
Demyan
Hi
Imagine a collection of personal data that includes, for each individual, his name (preceded by tag 'Name:'), his age (preceded by tag 'Age:'), and misc. stuff in between. I need to extract names and ages. I write a macro that loops over the following step
1. Find 'Name:'; retrieve the following word (name), paste it into output fil
2. Find 'Age:'; retrieve the following word (age), paste it into output file
(Code is attached below). It doesn't work: throughout all attempted tweaks, age is either not found, or found once, for person 1, and then repeated for all individuals. I am aware of Find's redefining Selection in case of a successful search, but both searches in my macro run in ActiveDocument.Content
A seemingly simple, but baffling task..I would be extremely grateful for a helpful suggestion
Thank you
Sub ExtractLabels(
Set DocIn = ActiveDocumen
Set ConIn = DocIn.Conten
Set DocOut = Documents("test"
Set ConOut = DocOut.Conten
Set WdBefore = ConIn.Fin
StopFlag =
Do While StopFlag =
'Find the word 'Name:
With WdBefor
.ClearFormattin
.Text = "Name:
.Forward = Tru
.Execut
End Wit
If WdBefore.Found = True The
'Record nam
ConOut.InsertAfter Text:=ConIn.Next(Unit:=wdWord)
'Find the word 'Age:
WdBefore.Execute FindText:="Age:", Forward:=Tru
If WdBefore.Found = True The
'Record the variable labe
ConOut.InsertAfter Text:=Chr(34) & WdBefore.Parent.Next(Unit:=wdWord, Count:=1) & Chr(34) & vbC
Els
StopFlag =
End I
Els
StopFlag =
End I
Loo
End Su
Imagine a collection of personal data that includes, for each individual, his name (preceded by tag 'Name:'), his age (preceded by tag 'Age:'), and misc. stuff in between. I need to extract names and ages. I write a macro that loops over the following step
1. Find 'Name:'; retrieve the following word (name), paste it into output fil
2. Find 'Age:'; retrieve the following word (age), paste it into output file
(Code is attached below). It doesn't work: throughout all attempted tweaks, age is either not found, or found once, for person 1, and then repeated for all individuals. I am aware of Find's redefining Selection in case of a successful search, but both searches in my macro run in ActiveDocument.Content
A seemingly simple, but baffling task..I would be extremely grateful for a helpful suggestion
Thank you
Sub ExtractLabels(
Set DocIn = ActiveDocumen
Set ConIn = DocIn.Conten
Set DocOut = Documents("test"
Set ConOut = DocOut.Conten
Set WdBefore = ConIn.Fin
StopFlag =
Do While StopFlag =
'Find the word 'Name:
With WdBefor
.ClearFormattin
.Text = "Name:
.Forward = Tru
.Execut
End Wit
If WdBefore.Found = True The
'Record nam
ConOut.InsertAfter Text:=ConIn.Next(Unit:=wdWord)
'Find the word 'Age:
WdBefore.Execute FindText:="Age:", Forward:=Tru
If WdBefore.Found = True The
'Record the variable labe
ConOut.InsertAfter Text:=Chr(34) & WdBefore.Parent.Next(Unit:=wdWord, Count:=1) & Chr(34) & vbC
Els
StopFlag =
End I
Els
StopFlag =
End I
Loo
End Su