title: Word Interop replace text
body: <p>I use following function to find and replace text:</p>
  
  <pre><code>Microsoft.Office.Interop.Word.Application wordApp = new Microsoft.Office.Interop.Word.Application { Visible = true };
  
  Microsoft.Office.Interop.Word.Document aDoc = wordApp.Documents.Open(fileName, ReadOnly: false, Visible: true);
              aDoc.Activate();
  FindAndReplace(wordApp, "A", "B");
  
  private void FindAndReplace(Microsoft.Office.Interop.Word.Application doc, object findText, object replaceWithText)
      {
          try
          {
              //options
              object matchCase = false;
              object matchWholeWord = true;
              object matchWildCards = false;
              object matchSoundsLike = false;
              object matchAllWordForms = false;
              object forward = true;
              object format = false;
              object matchKashida = false;
              object matchDiacritics = false;
              object matchAlefHamza = false;
              object matchControl = false;
              object read_only = false;
              object visible = true;
              object replace = 2;
              object wrap = 1;
              //execute find and replace
              doc.Selection.Find.Execute(ref findText, ref matchCase, ref matchWholeWord,
                  ref matchWildCards, ref matchSoundsLike, ref matchAllWordForms, ref forward, ref wrap, ref format, ref replaceWithText, ref replace,
                  ref matchKashida, ref matchDiacritics, ref matchAlefHamza, ref matchControl);
          }
          catch (Exception e)
          {
              throw e;
          }
      }
  </code></pre>
  
  <p>It works fine, but I wonder if there is any way to replace text "A" with "B" formated in other style? I mean ex: replace "A" <em>FontColor="Black"</em> with "B" <em>FontColor="Red"</em>.<br>
  In other words I wonder if it is possible to change the color of the text "A" or replace it with "B" colored with another color.</p>