There are two problems:
a. how do you iterate through the fields in text boxes?
b. how do you get information about a field when you have got a reference
to it?
For (a), you probably need to think about iterating through the Shapes
collection then using the Shape's range to iterate through the fields or
mergefields in that Shape.
e.g. to return the text of field 1 in Shape 1,
activedocument.Shapes(1).Select
(You may need to change these code snippets for C#, and in particular change
the indexes from 1-based to 0-based. I don't know).
For (b), it depends on what you want to do, but there are several properties
of a Field or MailMergeField - e.g.
Selection.Range.Fields(1).Code
When working with fields you can see how badly designed Ranges in Word are
because they rely on a character count which changes depending on whether
your field codes are displayed, and so on. So be careful using them!
Peter Jamieson
> Hi there,
>
[quoted text clipped - 16 lines]
> Any advise is welcome.
> Raul.
Raul - 31 Jan 2007 14:39 GMT
Peter,
Thanks for the help, It realy helped.
Here is the snippet in C#
Enumerator oFieldEnumerator = WordDoc.Shapes.GetEnumerator();
while(oFiledEnumerator.MoveNext())
{
Word.Shape oShape = oFieldEnumerator as Word.Shape;
// select the object
Object replace = Type.Missing;
oShape.Select(ref replace);
// I care about Text boxes only
if(oShape.Type == Microsoft.Office.Core.MsoShapeType.msoTextBox)
{
// note , to get the text you need to look at oShape.AlternativeText
// do what ever here
}
}
> There are two problems:
> a. how do you iterate through the fields in text boxes?
[quoted text clipped - 43 lines]
>> Any advise is welcome.
>> Raul.
Peter Jamieson - 31 Jan 2007 14:56 GMT
Raul,
Thanks for the useful feedback.
Peter Jamieson
> Peter,
>
[quoted text clipped - 65 lines]
>>> Any advise is welcome.
>>> Raul.