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

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