How can I check if the next word is numerical to determine action

So after Timothy Rylatt helped me with this question I am now having another problem. I only want to highlight the first word if the word that follows is numerical. I have tried to do so but it does not seem to be working. Any help would be appreciated and apologies if I am making any obvious errors I am (VERY) new to VB.

Sub feknew()
   Dim findRange As Range
   Dim nextWords As Range
   Dim NumChk  As Range
   
   Set findRange = ActiveDocument.Content
   With findRange.Find
      .ClearFormatting
      .Text = "í. "
      .Forward = True
      .Wrap = wdFindStop
      .Format = False
      .MatchCase = True
      .MatchWholeWord = False
      .MatchWildcards = False
      .MatchSoundsLike = False
      .MatchAllWordForms = False
      
      Set NumChk = findRange.Next(wdWord)
      If IsNumeric(NumChk) Then
      
                                   
         Do While .Execute = True
         'findRange is now the range of the match so set nextWords to the 2 next words
         Set nextWords = findRange.Next(wdWord)
         nextWords.MoveEnd wdWord, 3
         'look for the specific text in the next two words
         If InStr(nextWords.Text, "á") = 0 Then findRange.HighlightColorIndex = wdYellow
         'collapse and move findRange to the end of the match
         findRange.Collapse wdCollapseEnd
         findRange.Move wdWord, 4
      
      Loop
         End If
         End With
         End Sub


Read more here: https://stackoverflow.com/questions/64391222/how-can-i-check-if-the-next-word-is-numerical-to-determine-action

Content Attribution

This content was originally published by MANOL at Recent Questions - Stack Overflow, and is syndicated here via their RSS feed. You can read the original post over there.

%d bloggers like this: