Accessing mergefields within a header/footer and within a textbox

P

PromisedOyster

HELP

I am trying to write a piece of code that will iterate through all of
the mergefields in a word document. This works just great except when
I try to access mergefields in a header/footer that are enclosed in a
textbox.it fails to get these.

Consider the code below. The statement, shape.Select(ref oMissing);
in the commented out code
generates the following error:

This member cannot be accessed in this view.


foreach (Word.Range range in
_wordApp.ActiveDocument.StoryRanges)
{
Word.Range story = range;
while (story != null)
{
story.Select();
foreach (Word.Shape shape in
_wordApp.Selection.HeaderFooter)
{
/*
shape.Select(ref oMissing); // This
generates an error
foreach (Word.Field field in
_wordApp.Selection.Fields)
{
if (field.Type ==
Word.WdFieldType.wdFieldMergeField)
{
ProcessField(field.Code.Text);
}
}
*/
}
foreach (Word.Field field in story.Fields)
{
if (field.Type ==
Word.WdFieldType.wdFieldMergeField)
{
ProcessField(field.Code.Text);
}
}
story = story.NextStoryRange;
}

}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top