vbams-word

Find the last match


I need your help in finding the LAST match. Unfortunately, my pattern does not work as I need. I need to find the last match of a set of characters consisting of two characters "{{", one or more numbers, may be letters (but may not be) and two characters "}}". + these characters must be underlined and bold. For exxcample: {{000015}} or {{000026WRR}}. However, my version of the pattern necessarily searches for letters. The search also loops.

    myDocument.Range.Find.ClearFormatting
        
    With myDocument.Range
        With .Find

            .Text = "\{{2}[0-9]{1,}[A-z]*\}{2}"

            .Forward = True
            .Wrap = wdFindContinue
            .Format = True
            .Font.Bold = True
            .Font.Underline = True
                
            .MatchCase = True
            .MatchWholeWord = False
            .MatchAllWordForms = False
            .MatchSoundsLike = False
            .MatchWildcards = True
                
            .Execute
        End With

        Do While .Find.Found
      
            myStr = .Text
            .Collapse wdCollapseEnd
            .Find.Execute
        Loop
   End With
        
   MsgBox myStr

Solution

  • Try:

    .Text = "\{\{[0-9A-Z]@\}\}"