title: VBA search for string in document and check its color
body: <p>I tried to make a function to search for a string in a document and check what is the first char in the string that is colored in red.</p>
  
  <p>for example I know that my document contains the string "bread water juice peach wine". Imagine that the bold text is red colored. I want the function to return the int 19 (first red char - p).</p>
  
  <pre><code> Function check(stringToCheck As String) As Integer
  Dim oRng As Word.Range
  Set oRng = ActiveDocument.Content
  
  With oRng.Find
      ' to ensure that unwanted formats aren't included as criteria
      .ClearFormatting
      'You don't care what the text is
      .Text = stringToCheck
      'Loop for each match and set a color
      While .Execute
          MsgBox (oRng.Text)
          For i = 1 To 40
  'take the Nth char of the string an check if it's red
  'the following msgBox is working
  MsgBox (Mid(oRng, i, 1))
  If Mid(Orng, i, 1).Font.Color = wdColorRed Then
  'the following msgBox is not working which means the error is in the last line.
  MsgBox ("made it")
  check = i
  Exit Function
  End If
  Next i
  
      Wend
  
  End With
  
  
  End Function
  </code></pre>
  
  <p>every time I try to call the function I have the error "run time error 424 - object required".</p>
  
  <p>I added some msgboxes to see when is the function interrupted and added a comment in that place.</p>
  
  <p>what is the problem? how can I fix it?</p>