I have an existing word document which has a formatted mail merge field({ MERGEFIELD Payment_Date \@ "MMMM d,yyyy" }
).
When I pass a string(say (01/01/2016)) from C# to do a mail merge the code field.Select() selects the entire merge field and replaces it with the string I am passing and I lose the formatting.
How can I prevent this?
foreach (Microsoft.Office.Interop.Word.Field field in document.Fields)
{
if (field.Code.Text.Contains("Payment_Date"))
{
DateTime pDate = new DateTime(2016, 12, 30);
field.Select();
application.Selection.TypeText(pDate.ToString());
}
}
This is the code that I am using to do the mail merge.