0

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]);
      }
   }
}
Community
  • 1
  • 1
John Ernest Guadalupe
  • 6,379
  • 11
  • 38
  • 71

1 Answers1

1

I really dont think Extensions.GetFieldName is a inbuilt method.It could be user defined method and not present under interop.

Usually field names are retrieved like this

Int32 endMerge = fieldText.IndexOf("\\");
Int32 fieldNameLength = fieldText.Length - endMerge;
String fieldName = fieldText.Substring(11, endMerge - 11);

Please go through this link.There is a very clear code on how to retieve the FieldNames.

Prabhu Murthy
  • 9,031
  • 5
  • 29
  • 36