Using OR condition in findtext

J

Jay Freedman

Hi Vince,

Sorry, you are asking more than VBA can deliver. The standard way to
do this is to loop through the array (of either find text or styles or
any other criteria) and do a separate find for each. There is no
quicker way except the wildcard search that Doug mentioned.

Jonathan West suggested a speedup that will work with text (but not
styles): pull the entire text of the document into a huge string, and
use InStr() to test whether the current item in the array occurs
anywhere in that string. If so, use .Find to locate the item in the
document; if not, go on to test the next item.

--
Regards,
Jay Freedman http://aspnet2.com/mvp.ashx?JayFreedman
Microsoft Word MVP FAQ: http://www.mvps.org/word

fdde said:
Thank you for your reply. I guess I will have to stick to the array method
then. "AB" holds good only for single letter characters. It doesn't work
very well for super large strings. Also, is it possible to find any style
from a list of Styles using a range? I mean, can I have something like
Selection.find.style = "blah" or "blah" or "blah". Basically, I need to
change the text around if the style is one among many choices. The
conventional way to do this is to, of course, use an array. I was wondering
if anything quicker was possible. (Why do I get the feeling that I am asking
for too much!)

Many thanks.
Vince
Doug Robbins said:
If you could come up with a wildcard string that is met by both "A" and "B"
and nothing else, it could be done.

For A and B themselves, it would be [AB]{1} But I guess that is not really
what you meant.

--
Please respond to the Newsgroup for the benefit of others who may be
interested. Questions sent directly to me will only be answered on a paid
consulting basis.

Hope this helps,
Doug Robbins - Word MVP
fdde said:
Hi all,

I would like to know if it is possible to search for more than 1 text
using
find. I mean something like, Selection.find.execute findtext:="A" or "B"
and
so on...
I know I could use an array to do the search for each findtext string, but
something like this would make my life easy! Please let me know.

Thanks a lot.

Vince
 
F

fdde

Hi all,

I would like to know if it is possible to search for more than 1 text using
find. I mean something like, Selection.find.execute findtext:="A" or "B" and
so on...
I know I could use an array to do the search for each findtext string, but
something like this would make my life easy! Please let me know.

Thanks a lot.

Vince
 
D

Doug Robbins

If you could come up with a wildcard string that is met by both "A" and "B"
and nothing else, it could be done.

For A and B themselves, it would be [AB]{1} But I guess that is not really
what you meant.

--
Please respond to the Newsgroup for the benefit of others who may be
interested. Questions sent directly to me will only be answered on a paid
consulting basis.

Hope this helps,
Doug Robbins - Word MVP
 
F

fdde

Thank you for your reply. I guess I will have to stick to the array method
then. "AB" holds good only for single letter characters. It doesn't work
very well for super large strings. Also, is it possible to find any style
from a list of Styles using a range? I mean, can I have something like
Selection.find.style = "blah" or "blah" or "blah". Basically, I need to
change the text around if the style is one among many choices. The
conventional way to do this is to, of course, use an array. I was wondering
if anything quicker was possible. (Why do I get the feeling that I am asking
for too much!)

Many thanks.
Vince
Doug Robbins said:
If you could come up with a wildcard string that is met by both "A" and "B"
and nothing else, it could be done.

For A and B themselves, it would be [AB]{1} But I guess that is not really
what you meant.

--
Please respond to the Newsgroup for the benefit of others who may be
interested. Questions sent directly to me will only be answered on a paid
consulting basis.

Hope this helps,
Doug Robbins - Word MVP
fdde said:
Hi all,

I would like to know if it is possible to search for more than 1 text
using
find. I mean something like, Selection.find.execute findtext:="A" or "B"
and
so on...
I know I could use an array to do the search for each findtext string, but
something like this would make my life easy! Please let me know.

Thanks a lot.

Vince
 
F

fdde

Hey Jay,

Thank you for your reply. Well, I guess Arrays .... Here I come!

Vince

Jay Freedman said:
Hi Vince,

Sorry, you are asking more than VBA can deliver. The standard way to
do this is to loop through the array (of either find text or styles or
any other criteria) and do a separate find for each. There is no
quicker way except the wildcard search that Doug mentioned.

Jonathan West suggested a speedup that will work with text (but not
styles): pull the entire text of the document into a huge string, and
use InStr() to test whether the current item in the array occurs
anywhere in that string. If so, use .Find to locate the item in the
document; if not, go on to test the next item.

--
Regards,
Jay Freedman http://aspnet2.com/mvp.ashx?JayFreedman
Microsoft Word MVP FAQ: http://www.mvps.org/word

fdde said:
Thank you for your reply. I guess I will have to stick to the array method
then. "AB" holds good only for single letter characters. It doesn't work
very well for super large strings. Also, is it possible to find any style
from a list of Styles using a range? I mean, can I have something like
Selection.find.style = "blah" or "blah" or "blah". Basically, I need to
change the text around if the style is one among many choices. The
conventional way to do this is to, of course, use an array. I was wondering
if anything quicker was possible. (Why do I get the feeling that I am asking
for too much!)

Many thanks.
Vince
Doug Robbins said:
If you could come up with a wildcard string that is met by both "A" and "B"
and nothing else, it could be done.

For A and B themselves, it would be [AB]{1} But I guess that is not really
what you meant.

--
Please respond to the Newsgroup for the benefit of others who may be
interested. Questions sent directly to me will only be answered on a paid
consulting basis.

Hope this helps,
Doug Robbins - Word MVP
Hi all,

I would like to know if it is possible to search for more than 1 text
using
find. I mean something like, Selection.find.execute findtext:="A" or "B"
and
so on...
I know I could use an array to do the search for each findtext
string,
but
something like this would make my life easy! Please let me know.

Thanks a lot.

Vince
 

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