PDA

View Full Version : Match Case in Find does not work.



nhmabv
04-16-2012, 10:59 AM
I am attempting to find text with no regards to case. ".MatchCase = False" (or true) does not work.

This is what I am using:
With Selection.Find
.Forward = True

.MatchWholeWord = True

.MatchCase = False

.Wrap = wdFindContinue

.Font.Bold = False 'If I DONT put his in, it will only find Bold text

.Execute FindText:="Client"
End With
The word "client" below will not be found / selected.
".......bla bla bla client bla bla bla"

Here it will find and select the word "Client" , even with matchcase=False.
".......bla bla bla Client bla bla bla"

Thanks for any help

Paul_Hossler
04-16-2012, 11:28 AM
Put


.Format = False


in the Find loop and see if it gives the expected results

Paul

nhmabv
04-16-2012, 12:00 PM
.Format
Does not fix issue,
Mike

Tinbendr
04-16-2012, 01:15 PM
This finds 'Client' or 'client' on my machine.

Sub Text()
With Selection.Find
.Forward = True
.Format = False
.MatchCase = False
.MatchWholeWord = True
.Wrap = wdFindContinue
'.Font.Bold = False 'If I DONT put his in, it will only find Bold text
.Execute FindText:="Client"
End With
End Sub

Frosty
04-16-2012, 03:36 PM
You should record the macro which does this and use all of the items you find, or go away from the Selection object entirely and start to use the range object.

The problem you're having, I suspect, is that Selection.Find object can "remember" various settings. There are a lot of variables at play here, but why don't you start with showing us a recorded macro (if you are not a programmer) or use the range object (if you are) and tell us the version number.

Obviously .MatchCase as a property of the Find object for Microsoft Word is not entirely broken, so we'll probably need a few more details.

Remember to use the VBA tags, please!

nhmabv
04-16-2012, 08:53 PM
OK,

I did not realize that Word could record all of the options while recording. Here is what it recorded when I ran the recorder, which works.

Selection.Find.ClearFormatting
With Selection.Find
.Text = "Client"
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
.Font.Bold = True
End With
Selection.Find.Execute

I added the ".Font.Bold=True" , which also pays attention to bold words.

Thanks all for your input.
Mike

Frosty
04-16-2012, 10:17 PM
I believe that if you have .Format = False that will make .Font.Bold = True meaningless (i.e., you'll find the bold words regardless).

But you can play around with different finds while you record macros to see what shows up.

And check out the vba tags... bracket "[" and VBA and "]" and then close off your code with a backslash. There's also a button... it really makes your code much easier to read.

macropod
04-17-2012, 02:58 AM
Hi Mike,

Word will find both bold and non-bold text without the ".Font.Bold=True" directive. In fact, with that directive appearing after the ".Format = False" directive, it will only find bold text.

nhmabv
04-17-2012, 11:37 PM
OK,
After a lot more research,
".MatchWildCards" =True will render ".MatchCase" =False useless.
You can not search case insensitive. A search for "Mike * Johnson" will not find find "mike tom johnson", and a search for "Mike" will not find "mike'
Thanks Microsoft.
Mike

macropod
04-17-2012, 11:52 PM
Hi Mike,

Your 'Thanks Microsoft' speaks of intemperence instead of one taking the time to learn how to use the tools at their disposal.

It is true that ".MatchCase = True" is of no effect if ".MatchWildCards =True', but that doesn't mean you can't check for upper & lower cases in a wildcard Find. A wildcard Find for "[Mm]ike *[Jj]ohnson" will find:
mike johnson, mike Johnson, Mike johnson, Mike Johnson,
mike xxx johnson, mike xxx Johnson, Mike xxx johnson, Mike xxx Johnson,
mike tom dick harry johnson, mike tom dick harry Johnson, Mike tom dick harry johnson, Mike tom dick harry Johnson,
etc.

Wildcard Find/Replace expressions can be quite powerful. Consider:
Find = (<[MTWFSondayueshrit]{3,8},)( [JFMASONDanuryebchpilgstmov]{3,9})( [0-9]{1,2}[dhnrst]{2}),( [12][0-9]{3}>)
Replace = \1\3\2\4

Frosty
04-18-2012, 11:59 AM
Oldie but a goodie...
http://word.mvps.org/faqs/General/UsingWildcards.htm