I was browsing quite a lot of threads recently and came across this one:
Replace MergeFields in a Word 2003 document and keep style
It's an old thread but looks very promising since I got the logic of the code down and am sure I will be able to utilize it. The only problem I am facing is that I can't seem to declare/use this method?
Extensions.GetFieldName()
Any ideas to substitute it though would also be appreciated! :)
Here is the actual code I am trying to use
foreach (Field mergeField in document.Fields)
{
if (mergeField.Type == WdFieldType.wdFieldMergeField)
{
string fieldText = mergeField.Code.Text;
string fieldName = Extensions.GetFieldName(fieldText);
if (values.ContainsKey(fieldName))
{
mergeField.Select();
application.Selection.TypeText(values[fieldName]);
}
}
}