VBA Express Forum  




Go Back   VBA Express Forum > VBA Code & Other Help > Word Help
     Feedback     
Register FAQ Members Arcade Knowledge Base Training Articles Consulting

Reply
 
Thread Tools Display Modes
Old 04-16-2012, 10:59 AM   #1
nhmabv

 
Joined: Apr 2012
Posts: 18
Kb Entries: 0
Articles: 0
Question Match Case in Find does not work.

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

Local Time: 01:27 AM
Local Date: 05-20-2013
Location:

 
Reply With Quote Top
Old 04-16-2012, 11:28 AM   #2
Paul_Hossler

 
Joined: Apr 2007
Posts: 2,083
Kb Entries: 0
Articles: 0
Put

VBA:
.Format = False
VBA tags courtesy of www.thecodenet.com

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

Paul

Local Time: 05:27 AM
Local Date: 05-20-2013
Location:

 
Reply With Quote Top
Old 04-16-2012, 12:00 PM   #3
nhmabv

 
Joined: Apr 2012
Posts: 18
Kb Entries: 0
Articles: 0
.Format
Does not fix issue,
Mike

Local Time: 01:27 AM
Local Date: 05-20-2013
Location:

 
Reply With Quote Top
Old 04-16-2012, 01:15 PM   #4
Tinbendr
 
Tinbendr's Avatar

 
Joined: Jun 2005
Posts: 983
Kb Entries: 0
Articles: 0
This finds 'Client' or 'client' on my machine.

VBA:
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
VBA tags courtesy of www.thecodenet.com


+------+
| David |
+------+

Local Time: 03:27 AM
Local Date: 05-20-2013
Location:

 
Reply With Quote Top
Old 04-16-2012, 03:36 PM   #5
Frosty

 
Joined: Feb 2011
Posts: 1,354
Kb Entries: 0
Articles: 0
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!

Local Time: 05:27 AM
Local Date: 05-20-2013
Location:

 
Reply With Quote Top
Old 04-16-2012, 08:53 PM   #6
nhmabv

 
Joined: Apr 2012
Posts: 18
Kb Entries: 0
Articles: 0
Smile Match Case in Find does not work

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

Local Time: 01:27 AM
Local Date: 05-20-2013
Location:

 
Reply With Quote Top
Old 04-16-2012, 10:17 PM   #7
Frosty

 
Joined: Feb 2011
Posts: 1,354
Kb Entries: 0
Articles: 0
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.

Local Time: 05:27 AM
Local Date: 05-20-2013
Location:

 
Reply With Quote Top
Old 04-17-2012, 02:58 AM   #8
macropod
 
macropod's Avatar

 
Joined: Jul 2008
Posts: 1,922
Kb Entries: 0
Articles: 7
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.


Cheers
Paul Edstein
[MS MVP - Word]

Local Time: 07:27 PM
Local Date: 05-20-2013
Location:

 
Reply With Quote Top
Old 04-17-2012, 11:37 PM   #9
nhmabv

 
Joined: Apr 2012
Posts: 18
Kb Entries: 0
Articles: 0
Exclamation Match Case in Find does not work

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

Local Time: 01:27 AM
Local Date: 05-20-2013
Location:

 
Reply With Quote Top
Old 04-17-2012, 11:52 PM   #10
macropod
 
macropod's Avatar

 
Joined: Jul 2008
Posts: 1,922
Kb Entries: 0
Articles: 7
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


Cheers
Paul Edstein
[MS MVP - Word]

Local Time: 07:27 PM
Local Date: 05-20-2013
Location:

 
Reply With Quote Top
Old 04-18-2012, 11:59 AM   #11
Frosty

 
Joined: Feb 2011
Posts: 1,354
Kb Entries: 0
Articles: 0
Oldie but a goodie...
http://word.mvps.org/faqs/General/UsingWildcards.htm

Local Time: 05:27 AM
Local Date: 05-20-2013
Location:

 
Reply With Quote Top
Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump


All times are GMT -7. The time now is 02:27 AM.


Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Copyright © 2004 - 2012 VBA Express