M
Mark
This is a simple question. Please enlighten. I am using JScript to do
some Word automation. As far as the Word object model documentation is
concerned, unlike a Bookmark object, the Field object does not have a
Range property. You must select a Field object using the Select
method, then work with some resulting Selection to do things like
insert text into the document before or after the field.
The msdn doc is kind of baffling. It says the Select method "Selects
the specified object. Note After using this method, you can use the
Selection property to return a Selection object. For more information,
see Working with the Selection object." But the Selection property of
what object? How do you get from the Select method to a Selection you
can work with? None of the code samples or other doc clarify this.
Here is the chunk of code in question. Note in JScript you must use
Enumerations to handle Collections.
var fields = new Enumerator(workingdoc.Fields);
....
for (; !fields.atEnd(); fields.moveNext())
{
var thisfield = fields.item();
thisfield.Select();
var selectedfield = thisfield.Selection;
selectedfield.InsertAfter("huh");
}
When I run a script including this, I can see in my active, visible
document that the field is indeed selected on the screen
(thisfield.Select() works fine). However, I get an error saying
"'selectedfield' is null or not an object", so no text is inserted.
What's the easy thing I'm missing here?
Thank you.
some Word automation. As far as the Word object model documentation is
concerned, unlike a Bookmark object, the Field object does not have a
Range property. You must select a Field object using the Select
method, then work with some resulting Selection to do things like
insert text into the document before or after the field.
The msdn doc is kind of baffling. It says the Select method "Selects
the specified object. Note After using this method, you can use the
Selection property to return a Selection object. For more information,
see Working with the Selection object." But the Selection property of
what object? How do you get from the Select method to a Selection you
can work with? None of the code samples or other doc clarify this.
Here is the chunk of code in question. Note in JScript you must use
Enumerations to handle Collections.
var fields = new Enumerator(workingdoc.Fields);
....
for (; !fields.atEnd(); fields.moveNext())
{
var thisfield = fields.item();
thisfield.Select();
var selectedfield = thisfield.Selection;
selectedfield.InsertAfter("huh");
}
When I run a script including this, I can see in my active, visible
document that the field is indeed selected on the screen
(thisfield.Select() works fine). However, I get an error saying
"'selectedfield' is null or not an object", so no text is inserted.
What's the easy thing I'm missing here?
Thank you.