I have some code to replace text inside a word 2010 docx.
object fileName = Path.Combine(System.Windows.Forms.Application.StartupPath, "document.docx");
Microsoft.Office.Interop.Word.Application wordApp = new Microsoft.Office.Interop.Word.Application { Visible = true };
Microsoft.Office.Interop.Word.Document aDoc = wordApp.Documents.Open(ref fileName, ReadOnly: false, Visible: true);
aDoc.Activate();
Microsoft.Office.Interop.Word.Find fnd = wordApp.ActiveWindow.Selection.Find;
fnd.ClearFormatting();
fnd.Replacement.ClearFormatting();
fnd.Forward = true;
fnd.Wrap = Microsoft.Office.Interop.Word.WdFindWrap.wdFindContinue;
fnd.Text = "{id}";
fnd.Replacement.Text = "123456";
fnd.Execute(Replace: WdReplace.wdReplaceAll);
This works without formatting. But when {id} is formatted it does not replace the text.
How can I make this code ignore formatting?