Hello
I don't know if this thread is still active, but if so it addresses my topic exactly. I have a Word 2010 table with a drop down list (created by going to Developer tab => Drop-Down List Content Control, and then Properties). I don’t know if this means I am using form fields or not. I would like the cell background color (and font) to change based on the drop-down selection. I am using the code below, which is adapted from the code in the thread above. I don’t get an error message, but the cell background color doesn’t change either. I have editing restrictions enabled, and have highlighted the cells in the table that contain the drop-down list and allowed others to modify those cells. Any thoughts regarding how to make the code work so that the background (and font) change with the drop-down selection are much appreciated.
Code:
Private Sub Document_ContentControlOnExit(ByVal ContentControl As ContentControl, Cancel As Boolean)
Dim StrPwd As String
StrPwd = "DocumentPassword"
With ContentControl
If Len(.Title) < 4 Then Exit Sub
If Left(.Title, 4) = "Lst1" Then
If ActiveDocument.ProtectionType <> wdNoProtection Then ActiveDocument.Unprotect Password:=StrPwd
Select Case .Range.Text
Case "High": .Range.Cells(1).Shading.BackgroundPatternColorIndex = wdRed
Case "Medium": .Range.Cells(1).Shading.BackgroundPatternColorIndex = wdYellow
Case "Low": .Range.Cells(1).Shading.BackgroundPatternColorIndex = wdBrightGreen
Case Else: .Range.Cells(1).Shading.BackgroundPatternColorIndex = wdNoHighlight
End Select
ActiveDocument.Protect wdAllowOnlyFormFields, True, StrPwd
End If
If Left(.Title, 4) = "Lst2" Then
If ActiveDocument.ProtectionType <> wdNoProtection Then ActiveDocument.Unprotect Password:=StrPwd
Select Case .Range.Text
Case "High": .Range.Cells(1).Shading.BackgroundPatternColorIndex = wdRed
Case "Medium": .Range.Cells(1).Shading.BackgroundPatternColorIndex = wdYellow
Case "Low": .Range.Cells(1).Shading.BackgroundPatternColorIndex = wdBrightGreen
Case Else: .Range.Cells(1).Shading.BackgroundPatternColorIndex = wdNoHighlight
End Select
ActiveDocument.Protect wdAllowOnlyFormFields, True, StrPwd
End If
End With
End Sub