P
PromisedOyster
The following code iterates through all merge fields:
foreach (Word.Range range in _wordApp.ActiveDocument.StoryRanges)
{
Word.Range story = range;
while (story != null)
{
foreach (Word.Field field in story.Fields)
{
if (field.Type == Word.WdFieldType.wdFieldMergeField)
{
ProcessField(field.Code.Text);
}
}
story = story.NextStoryRange;
}
}
Unfortunately, if section 1's Header is blank but there is a section 2
Header, the above code doesn't work. It does not pick up the existence
of the section 2's Header
foreach (Word.Range range in _wordApp.ActiveDocument.StoryRanges)
{
Word.Range story = range;
while (story != null)
{
foreach (Word.Field field in story.Fields)
{
if (field.Type == Word.WdFieldType.wdFieldMergeField)
{
ProcessField(field.Code.Text);
}
}
story = story.NextStoryRange;
}
}
Unfortunately, if section 1's Header is blank but there is a section 2
Header, the above code doesn't work. It does not pick up the existence
of the section 2's Header