I am in the process of writing a small library that will perform a MailMerge on a word 2003 .DOT document in C#. I am able to retrieve and replace all of the document body fields like so:
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]);
}
}
}
But this does not retrieve the Header or Footer fields from the document..
I have tried this:
subscriptionDocument.Sections[1].Headers[WdHeaderFooterIndex.wdHeaderFooterPrimary].Range.Fields.Count;
To query the header fields, but am getting a count returned of "0", even though the fields physically exist.
Is there a way that I can do a achieve the desired affect on Header and Footer fields as well?