none
Find and match acute symbols in a word RRS feed

  • Question

  • HI ALL,

                In word document i have two paragraph, for example

      ****word document****

               The transportof sediment by rivers to the oceans represents an important Metan pathway in the global geochemical cycle, a key component of the global denudation system, and an important measure of land degradation and the associated reduction in the global soil resourceMetán

    The transportof sediment by rivers to the oceans represents an important pathway in the global geochemical cycle, a key component of the global denudation system, and an important measure of land degradation and the associated reduction Metán in the global soil resource

      ****word document end ****

    In the above document,First paragraph contains the name Metan( NOTE: character a is not acute) ,But Second Paragraph contains the name Metán (Here the character a is acute).So what  I want is ,I need to show the both word is same.Can any one tell me how to write a VBA code for this issue.

                                                    Thanks in advance

    Regards,

    Ruban.

     

    Wednesday, February 2, 2011 5:46 AM

Answers

  • Hi Peter,

    Your wildcard expression will find far more that just the words concerned.

    Ruban: Here's a macro that finds all words with accented characters-

    Sub Demo()
    Application.ScreenUpdating = False
    Dim StrWords As String
    With ActiveDocument.Content
      With .Find
        .ClearFormatting
        .Text = "[ÁáÉéÍíÓóÚú]"
        .Replacement.Text = ""
        .Forward = True
        .Wrap = wdFindStop
        .Format = False
        .MatchCase = False
        .MatchWholeWord = False
        .MatchWildcards = True
        .MatchSoundsLike = False
        .MatchAllWordForms = False
        .Execute
      End With
      Do While .Find.Found
        'Build a list of found words.
        If InStr(StrWords, "," & .Words(1).Text & ",") = 0 Then
          StrWords = StrWords & .Words(1).Text & ","
        End If
        'Highlight the found word.
        .Words(1).HighlightColorIndex = wdYellow
        .End = .Words(1).End + 1
        .Collapse (wdCollapseEnd)
        .Find.Execute
      Loop
    End With
    'Trim and output the list of found words.
    StrWords = Left(StrWords, Len(StrWords) - 1)
    MsgBox StrWords
    Application.ScreenUpdating = True
    End Sub

    The macro both highlights the found words and builds & outputs a list of them.


    Cheers
    Paul Edstein
    [MS MVP - Word]
    Wednesday, February 2, 2011 9:06 PM

All replies

  • Hi Ruban,

    The macro recorder will give you code very much like the following (which is actually quite efficient):

    Sub Demo()
      With Selection.Find
        .ClearFormatting
        .Replacement.ClearFormatting
        .Text = "Metan"
        .Replacement.Text = "Metán"
        .Forward = True
        .Wrap = wdFindContinue
        .Format = False
        .MatchCase = False
        .MatchWholeWord = False
        .MatchWildcards = False
        .MatchSoundsLike = False
        .MatchAllWordForms = False
        .Execute Replace:=wdReplaceAll
      End With
    End Sub


    Cheers
    Paul Edstein
    [MS MVP - Word]
    Wednesday, February 2, 2011 6:27 AM
  • Hi MACROPAD,

                       Thanks for reply,But actually I dont want to replace the word Metan to Metán.Document have lots of acute characters.When I pass the word Metan as argument,the macro will find all the word Metan as well as  Metán and report the count of Metan and Metán.

                                 Looking forward for your Reply.

    Regards,

    Ruban(MACRO DEVELOPER)

     

     

    Wednesday, February 2, 2011 9:33 AM
  • In this particular case, you can use a wildcard search (.MatchWildcards = True) for Met[aá]n

     


    Peter Jamieson
    Wednesday, February 2, 2011 11:38 AM
  • Hi Peter,

                      Not only for a and á.Document can have lots of acute symbols like this.I need a common code to check all cases and replace the particular acute symbols into character.

    regards,

    Ruban.

    Wednesday, February 2, 2011 12:16 PM
  • 1. I think you will need to try to clarify your specification before you can write code to do the job you want. For example

     a. do you want to specify the word(s) you want to search for, and search for all possible variations (e.g., you specify "metan" and the search looks for "metan" with every possible combination of accented and unaccented character. Or do you actually want to create a list of all words in the document which have more than one "version", where the versions are only different because of accented characters? Or something else? 

     b. dealing with "all cases" is a big thing to do - all cases with all acute accents? All cases with any kind of accented Latin character? Cases where the accent is part of the character only, or cases where the accent and the character are two separate Unicode characters in the text? Something else?

     


    Peter Jamieson
    Wednesday, February 2, 2011 12:50 PM
  • Thanks Peter,

                  Ya I knew that,Its very big thing to do. Ok can u sugges me ,to find that the particular word can have aute charaters or not.


    regards  

    Ruban

     

    Wednesday, February 2, 2011 1:17 PM
  • A wildcard find for

    <*[ÁÉÍÓÚáéíóú]*>

    would be a start. I assume you would be able to add other acute-accented letters if you need them, as long as there isn't a problem with Unicode characters in the Find. But this wouldn't find words where the accent was a separate Unicode character.


     


    Peter Jamieson
    Wednesday, February 2, 2011 2:30 PM
  • Hi Peter,

    Your wildcard expression will find far more that just the words concerned.

    Ruban: Here's a macro that finds all words with accented characters-

    Sub Demo()
    Application.ScreenUpdating = False
    Dim StrWords As String
    With ActiveDocument.Content
      With .Find
        .ClearFormatting
        .Text = "[ÁáÉéÍíÓóÚú]"
        .Replacement.Text = ""
        .Forward = True
        .Wrap = wdFindStop
        .Format = False
        .MatchCase = False
        .MatchWholeWord = False
        .MatchWildcards = True
        .MatchSoundsLike = False
        .MatchAllWordForms = False
        .Execute
      End With
      Do While .Find.Found
        'Build a list of found words.
        If InStr(StrWords, "," & .Words(1).Text & ",") = 0 Then
          StrWords = StrWords & .Words(1).Text & ","
        End If
        'Highlight the found word.
        .Words(1).HighlightColorIndex = wdYellow
        .End = .Words(1).End + 1
        .Collapse (wdCollapseEnd)
        .Find.Execute
      Loop
    End With
    'Trim and output the list of found words.
    StrWords = Left(StrWords, Len(StrWords) - 1)
    MsgBox StrWords
    Application.ScreenUpdating = True
    End Sub

    The macro both highlights the found words and builds & outputs a list of them.


    Cheers
    Paul Edstein
    [MS MVP - Word]
    Wednesday, February 2, 2011 9:06 PM