title: Re-defne a Paragraph Range to Include a Subset of Words in the Paragraph
body: <p>I'm using Microsoft.Interop.Word / C# to programmatically create a Word document. In a given paragraph, I need to change the color of words that occur between brackets "[" and "]" </p>
  
  <p>The words are variable.</p>
  
  <p>As I understand it, I need a Range object in order to set colors. I'm using the following code, which does not work:</p>
  
  <pre><code>// Add the paragraph.
  Microsoft.Office.Interop.Word.Paragraph pgf = document.Paragraphs.Add();
  
  // Insert text into the paragraph.
  pgf.Range.InsertBefore("JIRA Issue: " + jiraIssueId + " [" + statusName + "]");
  
  //Get start and end locations of the brackets.
  //These will define the location of the words to which I will apply colors.            
  int startPos = pgf.Range.Text.IndexOf("[") + 1;
  int endPos = pgf.Range.Text.IndexOf("]") - 1;
  
  /* Attempt to change range start and end positions,
   so the range contains just the words between brackets.
   I've tried two methods.                  
  */
  // The following line does not work.
  pgf.Range.SetRange(startPos, endPos);
  
  // And the following lines do not work either
  pgf.Range.Start = startPos;
  pgf.Range.End = endPos;
  
  // Attempt to Change color. The following line changes the color of entire paragraph:
  pgf.Range.Font.Color = Microsoft.Office.Interop.Word.WdColor.wdColorRed;
  
  /* The following always prints the entire contents of the paragraph, 
    and not just the words between the brackets. So my attempts at narrowing
    the range were not successful.
  */
  Console.WriteLine(pgf.Range.Text);
  </code></pre>