title: Generating replacement text from found text for Word addin, using VB.NET and Office-Interop
body: <p>I need to add correct stress accents to every word in a Microsoft Word document.  I have a script called "DoAccentuate" which determines the correct accentuation for any word that is input.  However, I don't know how to capture the currently selected found word, process it with my DoAccentuate script, and replace that same word with the result (without effecting the formatting of the text).  This is what I tried.</p>
  
  <pre><code>Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
      Dim document As Word.Document
      document = Globals.ThisAddIn.Application.ActiveDocument
  
      Dim FindObject As Word.Find = document.Application.Selection.Find
      With FindObject
          .ClearFormatting()
          .Text = "&lt;*&gt;"
          .MatchWildcards = True
          .Replacement.ClearFormatting()
          .Replacement.Text = DoAccentuate(document.Application.Selection.Text)
          .Execute(Replace:=Microsoft.Office.Interop.Word.WdReplace.wdReplaceAll)
  
      End With
  End Sub
  </code></pre>