• Find and Replace

    Author
    Topic
    #458993

    Hi there

    I need to be able to find, for example, the word ‘brother’ throughout a document when it occurs as a word on its own but not when it occurs as past of another word e.g. ‘brother-in-law’ and replace it with, say, ‘sister’. I had thought that the ‘whole words’ option would do this but it does not. This option seems to treat a dash as an indication an end of word (like a space). Please can someone tell me how I can achieve this?

    Many thanks for any help.

    ArchieD

    Viewing 4 reply threads
    Author
    Replies
    • #1155982

      I was not aware of this behaviour, but I have had a look and found that what you say is correct, however to overcome the action I checked the box “Use Wildcards” this worked for me in Word 2003.
      By the way your link at the bottom of your post is (I think) incorrect.

    • #1155985

      I need to be able to find, for example, the word ‘brother’ throughout a document when it occurs as a word on its own but not when it occurs as past of another word e.g. ‘brother-in-law’ and replace it with, say, ‘sister’.

      We recently had a thread about a Find using Word’s wildcard search feature to look for a word between certain desired “boundary” characters. The problem was that the find included the boundary characters, so it would have to be tweaked a bit to replace only the word between them. It’s late here, so I can’t work on it now, but here is the other thread for reference: Find Upper Case Whole Words.

    • #1155994

      Hi there

      I need to be able to find, for example, the word ‘brother’ throughout a document when it occurs as a word on its own but not when it occurs as past of another word e.g. ‘brother-in-law’ and replace it with, say, ‘sister’. I had thought that the ‘whole words’ option would do this but it does not. This option seems to treat a dash as an indication an end of word (like a space). Please can someone tell me how I can achieve this?

      Many thanks for any help.

      ArchieD

      I can give you two more simple ways – 1 quick, 1 reuseable

      Quick – first Find/Replace “brother-” and replace with something like “**CHANGEBACK**” then do your other replacements – then change it back to “brother-” – negates the issue!

      Reusable – Create a macro that finds (for example) “brother ” (note the space), then edit the macro in the VBA window.

      [codebox]Sub Macro1()

      ‘ Macro1 Macro
      ‘ Find and replace multiple forms of a word.

      Selection.Find.ClearFormatting
      Selection.Find.Replacement.ClearFormatting
      With Selection.Find
      .Text = “brother ”
      .Replacement.Text = “anything ”
      .Forward = True
      .Wrap = wdFindContinue
      .Format = False
      .MatchCase = False
      .MatchWholeWord = False
      .MatchWildcards = False
      .MatchSoundsLike = False
      .MatchAllWordForms = False
      End With
      Selection.Find.Execute Replace:=wdReplaceAll
      End Sub[/codebox]

      You can then copy and repeat the WITH statement to have any and all variants of our word “brother.” “brothers” etc. and if there is a specific variant that you want to be left alone, then you could always add a WITH statement at the beginning that alters it to something like “**CHANGEBACK**” and another at the end of the code that looks for “**CHANGEBACK** and turns it into what it should be:

      [codebox]Sub Macro2()

      ‘ Macro2 Macro
      ‘ Find and replace multiple forms of a word.

      Selection.Find.ClearFormatting
      Selection.Find.Replacement.ClearFormatting
      With Selection.Find
      .Text = “brother-”
      .Replacement.Text = “**CHANGEBACK**”
      .Forward = True
      .Wrap = wdFindContinue
      .Format = False
      .MatchCase = False
      .MatchWholeWord = False
      .MatchWildcards = False
      .MatchSoundsLike = False
      .MatchAllWordForms = False
      End With

      With Selection.Find
      .Text = “brother ”
      .Replacement.Text = “anything ”
      .Forward = True
      .Wrap = wdFindContinue
      .Format = False
      .MatchCase = False
      .MatchWholeWord = False
      .MatchWildcards = False
      .MatchSoundsLike = False
      .MatchAllWordForms = False
      End With

      With Selection.Find
      .Text = “**CHANGEBACK**”
      .Replacement.Text = “brother-”
      .Forward = True
      .Wrap = wdFindContinue
      .Format = False
      .MatchCase = False
      .MatchWholeWord = False
      .MatchWildcards = False
      .MatchSoundsLike = False
      .MatchAllWordForms = False
      End With
      Selection.Find.Execute Replace:=wdReplaceAll
      End Sub[/codebox]

      If you have this embedded in your Normal.dot Template, then all you have to do whenever you need to use it is Alt+F11 to open your VBA window and alter it as needed for the task.

      Bird

    • #1156015

      Why not try replacing the expression “_brother_ ” (where _ = space) with, say, “_sister_”. Of course this wouldn’t catch a sentence that began with the word Brother, but you could try finding these with an expression like “Brother_” (with Match case turned on). For an end of sentance use “_brother.” as the search term.

    • #1156050

      I am pleased to know that I was not missing something obvious. Thank you all very much for your replies and your suggestions.

      Thanks too for pointing out the incorrect link.

      ArchieD

    Viewing 4 reply threads
    Reply To: Find and Replace

    You can use BBCodes to format your content.
    Your account can't use all available BBCodes, they will be stripped before saving.

    Your information: