Change Color

D

Debra Ann

I have a table cell with a drop down field with four options (good, caution,
problem, fix). Depending on the user's pick, I want the table cell to change:

If good then green
If caution, then yellow
etc.

What is the code to do this?
 
G

Greg Maxey

Something like this:

Option Explicit
Public mstrFF As String

'Run on exit from your DD field

Public Sub AOnExit()
Dim oDoc As Word.Document
Dim oCell As Cell
Set oCell = ActiveDocument.Tables(1).Cell(1, 1)
Set oDoc = ActiveDocument
oDoc.Unprotect
With GetCurrentFF
Select Case .Name
Case Is = "MyDropDown"
Select Case .Result
Case Is = "good"
oCell.Shading.BackgroundPatternColor = wdColorGreen
Case Is = "caution"
oCell.Shading.BackgroundPatternColor = wdColorYellow
Case Else
'Whatever
End Select
Case Else
'Whatever
End Select
End With
oDoc.Protect wdAllowOnlyFormFields, True
End Sub


Public Function GetCurrentFF() As Word.FormField
With Selection
If .FormFields.Count = 1 Then
Set GetCurrentFF = .FormFields(1)
ElseIf .FormFields.Count = 0 And .Bookmarks.Count > 0 Then
Set GetCurrentFF = ActiveDocument.FormFields _
(.Bookmarks(.Bookmarks.Count).Name)
End If
End With
End Function
 

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