View Single Post
  #4   Report Post  
Posted to microsoft.public.word.tables
Graham Mayor Graham Mayor is offline
external usenet poster
 
Posts: 19,312
Default Conditional Cell Color

You have to protect the document for forms for legacy fields to work.
You should find http://gregmaxey.mvps.org/Classic%20Form%20Controls.htm
useful.

--

Graham Mayor - Word MVP

My web site www.gmayor.com
Word MVP web site http://word.mvps.org



WillW wrote:
Thanks, Graham -- It took me a while to get back to this, but I can
see the possibility of its working.

A basic problem for me, though: I can't make the Dropdown1 legacy
control function as a dropdown. It just sits there looking grey with
no hint of a dropdown. When I step through the macro, the background
color changes appropriately (matching the word that happens to be
displayed), but I'm not able to select the color from the legacy
control. And exiting the control doesn't change the color of A1.

What am I doing wrong? (Entering "legacy form control" in Word Help is
useless)

Thanks

"Graham Mayor" wrote:

If you use legacy form fields in your document, as suggested by Doug
in response to your other query, and one of those fields is a
dropdown fiild containing the three values, then you can certainly
format a cell of the table based on the selected content of that
dropdown field by running a macro on exit from the field. The
following, for example, will colour the first cell of the table
.Cell(1, 1) according to the result of the field

Sub ColorCellA1()
Dim sColor As String
Dim bProtected As Boolean
With ActiveDocument
If .ProtectionType wdNoProtection Then
bProtected = True
.Unprotect Password:=""
End If
With .Tables(1).Cell(1, 1).Shading
Select Case
LCase(ActiveDocument.FormFields("Dropdown1").Resul t)
Case Is = "red" .BackgroundPatternColor = wdColorRed
Case Is = "yellow"
.BackgroundPatternColor = wdColorYellow
Case Is = "green"
.BackgroundPatternColor = wdColorGreen
End Select
End With
If bProtected = True Then
.Protect _
Type:=wdAllowOnlyFormFields, _
NoReset:=True, _
Password:=""
End If
End With
End Sub

You may find the examples at
http://www.gmayor.com/word_vba_examples.htm and
http://www.gmayor.com/SelectFile.htm useful.

--

Graham Mayor - Word MVP

My web site www.gmayor.com
Word MVP web site http://word.mvps.org




WillW wrote:
I saw some other questions regarding conditional formating in Word
tables, so I don't hold out much hope for this. But it seems simple
enough that there might be some relatively easy way to do it.

Here's the situation: In a cell in the top row of a table in my
Word template, only 3 values are possible to select using a
control: Green, Yellow, Red. Can I make Word change the cell fill
color based on the option selected?

I tried using an embedded Excel table, but it just doesn't seem to
be the right solution in this case, and my manager doesn't want to
use Excel for the whole document as I suggested.

Thanks