shahjapan_2005


I am using MailMerge for custom data using C# Word Interop Assembly.

Word doesnt allow Merge field in Header Footer,
so is there any way that we can detect that Word Contains MailMerge field in header or footer.

Regards,
Japan Shah



Re: Visual Studio Tools for Office can we detect header footter contains mailmerge field or not ?

Cindy Meister

You really do need to remember to post the VERSION of the Office application you're working with. Things do change across versions...

You loop through all sections in the document. Pick up the RANGE for each header and each footer for the range (wdHeaderFooterPrimary, etc.) Loop through all the fields in that range and check the TYPE property of the field.

Note: As I recall, whether merge fields are supported in a header/footer depends on the type of mail merge being executed. They make no sense in a lable or envelop merge, but they should work in a letter merge. A directory (or catalog) merge rejects them because the result would be meaningless (Word doesn't know from which record the data should come when multiple records appear on a page.)






Re: Visual Studio Tools for Office can we detect header footter contains mailmerge field or not ?

shahjapan_2005



Word.Range headfootRange = activeDoc.Sections[1].Headers[Word.WdHeaderFooterIndex.wdHeaderFooterPrimary].Range;
foreach (Word.Field field in headfootRange.Fields)
{
if (field.Type == Microsoft.Office.Interop.Word.WdFieldType.wdFieldMergeField)
///do your processing
}