Text Highlighting with Drop Down Form Fields

R

Robin1979

Hello

I am familar with using drop down form fields in my documents however I
would like to be able on a current document against one of the drop down
fields to have the text highlighted in a certain colour depending on which
item is selected from the drop down.
For example when the word "closed" is selected from the drop down I would
like that to be highlighted in green, the word "open" highlighted in red all
automatically...!

Any ideas?

Thanks
Robin
 
G

Greg Maxey

Robin,

I am not sure, but I don't think there is a way to reflect the change until
the user exits the field. Run the following on exit from a dropdown with
values
Open and Close:

Sub HLDropdown()
Dim oFld As FormField
Dim oColor As WdColor
For Each oFld In Selection.FormFields
If oFld.Type = wdFieldFormDropDown Then
Select Case oFld.DropDown.Value
Case 1
oColor = wdRed
Case 2
oColor = wdGreen
Case Else
oColor = wdAuto
End Select
oFld.Select
With Selection
'To change font color of dropdown only stet out the next line.
.Sections(1).ProtectedForForms = False
.Range.HighlightColorIndex = oColor
.Sections(1).ProtectedForForms = True
End With
End If
Next oFld
End Sub
 
R

Robin1979

Hi, me again!

Is there anyway to make this Macro trusted in anyway - I have changed my
macros to be low or medium security on Office XP (on another PC) and also the
same on Office 2003 but it says that the macros in the project are disabled.
 
D

Doug Robbins - Word MVP

You should put the template containing the macro in the User Templates
Folder or the Work Group Templates Folder, the locations of which you can
determine by selecting Options from the Tools menu and then go to the File
Locations tab. Of course this requires that your form be saved as a
template and that you create a new document from it by selecting New from
the File menu and then select the template containing the form as the basis
for the document that you want to produce.

--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP
 

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