Consulting

Results 1 to 11 of 11

Thread: Match Case in Find does not work.

  1. #1
    VBAX Regular
    Joined
    Apr 2012
    Posts
    24
    Location

    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

  2. #2
    VBAX Sage
    Joined
    Apr 2007
    Location
    United States
    Posts
    8,711
    Location
    Put

    [VBA]
    .Format = False
    [/VBA]

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

    Paul

  3. #3
    VBAX Regular
    Joined
    Apr 2012
    Posts
    24
    Location
    .Format
    Does not fix issue,
    Mike

  4. #4
    VBAX Expert Tinbendr's Avatar
    Joined
    Jun 2005
    Location
    North Central Mississippi (The Pines)
    Posts
    993
    Location
    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]

    David


  5. #5
    VBAX Master
    Joined
    Feb 2011
    Posts
    1,480
    Location
    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!

  6. #6
    VBAX Regular
    Joined
    Apr 2012
    Posts
    24
    Location

    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

  7. #7
    VBAX Master
    Joined
    Feb 2011
    Posts
    1,480
    Location
    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.

  8. #8
    Knowledge Base Approver VBAX Guru macropod's Avatar
    Joined
    Jul 2008
    Posts
    4,435
    Location
    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
    [Fmr MS MVP - Word]

  9. #9
    VBAX Regular
    Joined
    Apr 2012
    Posts
    24
    Location

    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

  10. #10
    Knowledge Base Approver VBAX Guru macropod's Avatar
    Joined
    Jul 2008
    Posts
    4,435
    Location
    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
    [Fmr MS MVP - Word]

  11. #11

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •