Find object variables

C

Conan Kelly

Hello all,

Is there a way to create a Find Object variable?

I would like to create 2 different Find Object variables and assign different "text to find" (selection.find.text property) to each
variable where they won't interfere with/change one another.

Is this possible? If so, please provide sample code.
 
J

Jean-Guy Marcil

Conan Kelly was telling us:
Conan Kelly nous racontait que :
Hello all,

Is there a way to create a Find Object variable?

I would like to create 2 different Find Object variables and assign
different "text to find" (selection.find.text property) to each
variable where they won't interfere with/change one another.
Is this possible? If so, please provide sample code.

I am not sure I follow what you intend to do...

Why not just run the Find twice, back to back?

You could have a parameterized Function that accept the "text" as a
parameter and return the result.

--
Salut!
_______________________________________
Jean-Guy Marcil - Word MVP
(e-mail address removed)
Word MVP site: http://www.word.mvps.org
 
C

Conan Kelly

Jean-Guy,

Thank you for your feed back.

I guess that I will have to do that.

I have a long report. At the end of each section in the report, there is a summary on that section. Sometimes that summary can
spill over onto the next page.

I was trying to search for the string for the start of the first summary so I can find the starting position of the first summary.
Then I was searching for the next page break: the end of that summary. After I select the summary and cut it out, I now need to
search for a 2nd page of the same summary. I was doing this by using a Do While loop:

Selection.Find.Text = pstrSearchStrings(pintIndex)
Do While Selection.Find.Execute

well, within my Do While loop, I need to switch the text to look for the page break:

Selection.Find.Execute "^m"

now, if I don't switch my Find.Text back to the original setting, the Do While loop will not work correctly:

Selection.Find.Text = pstrSearchStrings(pintIndex)
Do While Selection.Find.Execute
...
Selection.Find.Execute "^m"
...
...
Selection.Find.Text = pstrSearchStrings(pintIndex)
Loop

I was hoping that it was possible to create 2 different Find Object variables and set the Find.Text for each of those variables to
somthing different. Something like:

Dim pfndPageBreak as New Find
Dim pfndSummaryText as New Find

pfndPageBreak.Text = "^m"
pfndSummaryText.Text = pstrSearchStrings(pintIndex)

and then my Do While would look something like this:

Do While pfndSummaryText.Execute
...
pfndPageBreak.Execute
...
...
'Selection.Find.Text = pstrSearchStrings(pintIndex) '<-- This line would not be needed anymore
Loop

But that doesn't work. As soon as I switch to look for a page break, it changes my Find.Text in the whole application and if I
don't reset my Find.Text back to it's original setting, the Do While loop won't work correctly.

Thanks again for all of your help,

Conan Kelly
 
J

Jean-Guy Marcil

Conan Kelly was telling us:
Conan Kelly nous racontait que :
Jean-Guy,

Thank you for your feed back.

I guess that I will have to do that.

I have a long report. At the end of each section in the report,
there is a summary on that section. Sometimes that summary can spill
over onto the next page.
I was trying to search for the string for the start of the first
summary so I can find the starting position of the first summary.
Then I was searching for the next page break: the end of that
summary. After I select the summary and cut it out, I now need to
search for a 2nd page of the same summary. I was doing this by using
a Do While loop:
Selection.Find.Text = pstrSearchStrings(pintIndex)
Do While Selection.Find.Execute

well, within my Do While loop, I need to switch the text to look for
the page break:

You could try something like this instead:

Dim strSummary As String

strSummary = "Summary"

Selection.HomeKey wdStory

With Selection.Find
.Text = strSummary
Do While .Execute
With Selection
.MoveEndUntil Chr(12), wdForward
.MoveRight wdCharacter, 1, wdExtend
.Delete
End With
Loop
End With


--
Salut!
_______________________________________
Jean-Guy Marcil - Word MVP
(e-mail address removed)
Word MVP site: http://www.word.mvps.org
 

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