Change color of text field

J

Justin

I am trying to create a condition in Word where if a certain option in a drop
down box is selected, then a blank text field box changes colors. Is this
possible?

For example: There is a yes or no question in a drop down box. If I select
"Yes", then the other blank text box stays grey. If I select "No", then
there is a text box that changes to red, which indicates that an explaination
should be entered in this area.
 
H

Helmut Weber

Hi Justin,

I'm assuming, you are talking about formfields.

Sub FormFields2Result()
With ActiveDocument.FormFields
If .Item(2).Result = "yes" Then
.Item(1).Range.HighlightColorIndex = wdYellow
End If
If .Item(2).Result = "no" Then
.Item(1).Range.HighlightColorIndex = wdRed
End If
End With
End Sub

There is a small drawback if you got only 2 formfields.
I don't know about vb.net,
but since you are asking in a VBA group,
you might be able to adapt the code yourself.

FormFields2Result would be the exit-macro
of formfield 2.

HTH

--
Greetings from Bavaria, Germany

Helmut Weber, MVP WordVBA

Win XP, Office 2003
"red.sys" & Chr$(64) & "t-online.de"
 

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