Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations John Tel on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

FormFields Style 1

Status
Not open for further replies.

victorbello

Programmer
Sep 26, 2006
1
US
Is there a way to go through all the FormFields in a document and change their style all together?

i'm trying this:

For Each mFormField In ActiveDocument.FormFields()
<--MISSING CODE-->
Selection.Style = "Any style"
Next

But i'm missing the sentence there to select mFormField before applying the style.

Thanks

VB
 
There is no need to select them.
Code:
Dim oFF As Word.FormField
If ActiveDocument.ProtectionType = wdAllowOnlyFormFields Then
    ActiveDocument.Unprotect
End If
For Each oFF In ActiveDocument.FormFields
    oFF.Range.Style = "Formfields"
Next
ActiveDocument.Protect wdAllowOnlyFormFields, NoReSet:=True

1. You must unprotect the document first - assuming it IS protected. Which it would be if you are using formfields.

2. The Style to be applied should probably be a Character style - not a paragraph style. If the formfield is within a paragraph then you may get undesired results.

Gerry
My paintings and sculpture
 
Just a note. You can of course use a Paragraph style to change the formfields if they are the only thing in the paragraph. It is just that often paragraph styles have a setting for NEXT paragraph. Well, actually, they always do. So any additional text put immediately following may have a style you do not want.

On the other hand, character styles that are immediately followed by a pilcrow (a paragraph mark) make the charcters in the next paragraph the same character style.

So it can do unexpected things regardless. You need to test your results. If you use a character style and it messes up text following, then you can run code to change the formfield style (with a character style), move the Selection to the formfield end, collapse it, explicitly change the style to NOT the character style, insert a space, then backspace to remove it.

What can I say? It is Word.

Gerry
My paintings and sculpture
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top