how to change textfield values?

H

Holger Kreißl

Question to VBA and Word >= 2000

Hi,

i want to write an rewrite values of textfields.

word example: {field1} {field2} {field3}

I figured out, that I can get the fieldnames in that way:

int_count = ActiveDocument.Fields.Count
For iterator = 1 To int_count
Code = ActiveDocument.Fields.Item(iterator).Code
com = InStr(Code, updatestring)
If (com > 0) Then
iFieldIndex = iterator
Exit For
End If
Next iterator
(Is there a way to reference the field directly with the fieldname? Without
iterating all fields?)

So I get the object of that field an try to overwrite the field content. I
do that in this way:
ActiveDocument.Fields.Item(iFieldIndex).Result.Text = value

But it doesn't work in that way I want. That command does not overwrite the
old value. It writes the text at the end of the existing text :-/

Is my way the wrong way to change the value of a textfield? Maybe does
somebody have an better example or some ideas

thank you,
Holger
 
A

Astrid

Hi Holger,

What kind of fields are you talking about? Are they formfields for example?
If so, you can set the result of the field by:
ActiveDocument.Formfields("NameOfField").Result = "New text here"

If you're talking about other type of fields, you can rewrite the code inside the field, not the result. If you post some more specifics we can try to help you out with this.

Hope this helps,
regards,
Astrid

So that all can benefit from the discussion, please post all follow-ups to the newsgroup.
Visit the MVP Word FAQ site at http://www.mvps.org/word/
 

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