How to read protected fields from VBA

M

Maurice W. Darr

Is it possible to set up a word document so the format and text cannot be
changed but the field information can be read with vba. It seems that the
inability to select the contents of a field from code prevents reading it.

Maurice
 
J

Jay Freedman

Is it possible to set up a word document so the format and text cannot be
changed but the field information can be read with vba. It seems that the
inability to select the contents of a field from code prevents reading it.

Maurice

Hi Maurice,

The key here is that you don't have to select anything in order to
read the field contents from VBA.

Each form field has a name (the entry in the "Bookmark" box in the
field's Properties dialog, which you can change to make it meaningful
instead of the default like Text1). If you know which field you want
to read and you know its name, your macro can assign its contents to a
string variable this way:

myString = ActiveDocument.FormFields("Text1").Result

Look at the code in
http://word.mvps.org/FAQs/TblsFldsFms/ValidateFFields.htm for more
examples of how to do this.

--
Regards,
Jay Freedman
Microsoft Word MVP
Email cannot be acknowledged; please post all follow-ups to the
newsgroup so all may benefit.
 
M

Maurice W. Darr

Jay,

That worked perfectly. I can read and write the form fields. I tried result
in the fields collection and it did not work there so its the formfields
collection that allows access. Makes sense.
Is there a good discussion of working with security in forms anywhere?

Maurice
 
Top