title: Adding border to a table row containing certain string in word vba
body: <p>I have a word document that is being generated from my program and currently have a macro that replaces <code>&lt;BR/&gt;</code> tags with a newline. This signifies the start of a new section in the table so I also wanted to add a border to the top of that row where the <code>&lt;BR/&gt;</code> tag occurs. My current code is:</p>
  
  <pre><code>With ActiveDocument.Content.Find
      .Text = "&lt;BR/&gt;"
      .Forward = True
      While .Execute
          .Parent.Text = Chr(10)
          .Parent.Collapse wdCollapseEnd
      Wend
  End With
  </code></pre>
  
  <p>How could I get the entire row in the table where <code>&lt;BR/&gt;</code> occurs and then add a border to it?</p>
  
  <p>My attempt so far was to add at end of the while loop after Collapse:</p>
  
  <pre><code>With .Parent.Row.Borders(wdBorderTop)
      .LineStyle = wdLineStyleSingle
      .LineWidth = wdLineWidth050pt
      .Color = wdColorAutomatic
  End With
  </code></pre>
  
  <p>But that does not do anything (also no error). I do not think I am grabbing the row correctly but I can not find any other way of doing it. Thanks.</p>
  
  <p>EDIT:</p>
  
  <p>I am now thinking maybe I should do a separate check before the newline part. So adding a for loop to loop through all table rows, check if <code>&lt;BR/&gt;</code> exists and if it does add a border to the top of the row.</p>
  
  <p>I am not used to vba in word, usually use excel so think I might be mixing the two. Here is what I have got so far:</p>
  
  <pre><code>Dim oTbl As Table
    Set oTbl = ActiveDocument.Tables(1)
  
    For Each oRow In oTbl.Rows
      If InStr(1, oRow.Cell(1, 1), "&lt;BR/&gt;", vbBinaryCompare) &gt; 0 Then
          oRow.Borders(wdBorderBottom).LineStyle = wdLineStyleSingle
      End If
    Next 
  </code></pre>