H
hr38581
I am creating an MS Word macro that should search the first section of the
document for specific text, copy all text in the paragraph (that contained
the found text), and paste the text in a table in a new document. (Repeat
for section 2 but with different search criteria).
I am creating arrays to store all the found text. At the end of the macro I
create a new doc with a new table and enter all the data from the arrays.
My problem is with limiting each search to its appropriate section. (I
don't want my Section 1 search to return text found in Section 2 (or other
sections) of the doc.)
Here is a portion of my code (there are additional loops within my search
that are not included here):
Selection.HomeKey Unit:=wdStory
Do While ActiveDocument.Bookmarks("\Section") = ActiveDocument.Sections(1)
With Selection.Find
.ClearFormatting
.Forward = True
Do While .Execute(FindText:="Test Name : ") = True
Selection.Bookmarks("\Para").Select
a = a + 1
ReDim Preserve PrePlanName(a)
Set PrePlanName(a) =
ActiveDocument.Range(Start:=Selection.Start, _
End:=Selection.End)
Selection.Collapse Direction:=wdCollapseEnd
Loop
End With
Loop
I get a type mismatch on my comparison between
'ActiveDocument.Bookmarks("\Section")' and 'ActiveDocument.Sections(1)'. So
how do I compare "current section" with "Section 1 of the doc"?
document for specific text, copy all text in the paragraph (that contained
the found text), and paste the text in a table in a new document. (Repeat
for section 2 but with different search criteria).
I am creating arrays to store all the found text. At the end of the macro I
create a new doc with a new table and enter all the data from the arrays.
My problem is with limiting each search to its appropriate section. (I
don't want my Section 1 search to return text found in Section 2 (or other
sections) of the doc.)
Here is a portion of my code (there are additional loops within my search
that are not included here):
Selection.HomeKey Unit:=wdStory
Do While ActiveDocument.Bookmarks("\Section") = ActiveDocument.Sections(1)
With Selection.Find
.ClearFormatting
.Forward = True
Do While .Execute(FindText:="Test Name : ") = True
Selection.Bookmarks("\Para").Select
a = a + 1
ReDim Preserve PrePlanName(a)
Set PrePlanName(a) =
ActiveDocument.Range(Start:=Selection.Start, _
End:=Selection.End)
Selection.Collapse Direction:=wdCollapseEnd
Loop
End With
Loop
I get a type mismatch on my comparison between
'ActiveDocument.Bookmarks("\Section")' and 'ActiveDocument.Sections(1)'. So
how do I compare "current section" with "Section 1 of the doc"?