View Single Post
 
Old 03-13-2018, 02:09 PM
anakuprava anakuprava is offline Windows 10 Office 2016
Novice
 
Join Date: Mar 2018
Posts: 4
anakuprava is on a distinguished road
Default

Hello
I am having the same problem as user Palmiema in previous posts and I can not figure out why the code I am using is not working.
I have a Word 2016 table with a drop down list (created by going to Developer tab => Drop-Down List Content Control, and then Properties). I would like the cell background color to change based on the drop-down selection (A, B and C). I am using the code below, there might be some basic mistake that I am making, as I don't know how to work with macros and have copied the code from here and adopted to my file. I don’t get an error message, but the cell background color doesn’t change either. I have attached the word file as well and would appreciate your advise on how to make the code work so that the background change with the drop-down selections.

Code:
Private Sub Document_ContentControlOnExit(ByVal ContentControl As ContentControl, Cancel As Boolean)
Const StrPwd As String = "abc"
With ContentControl
  Select Case .Title
    Case "Rating"
      If ActiveDocument.ProtectionType <> wdNoProtection Then ActiveDocument.Unprotect Password:=StrPwd
      With .Range
        Select Case .Text
          Case "A"
            .Cells(1).Shading.BackgroundPatternColorIndex = wdRed
            .Font.ColorIndex = wdRed
          Case "B"
            .Cells(1).Shading.BackgroundPatternColorIndex = wdYellow
            .Font.ColorIndex = wdOrange
          Case "C"
            .Cells(1).Shading.BackgroundPatternColorIndex = wdBrightGreen
            .Font.ColorIndex = wdYellow
          Case Else
            .Cells(1).Shading.BackgroundPatternColorIndex = wdNoHighlight
            .Font.ColorIndex = wdAuto
        End Select
      End With
      ActiveDocument.Protect wdAllowOnlyFormFields, True, StrPwd
  End Select
End With
End Sub
Thank you
Attached Files
File Type: docm 1st page v.2.docm (23.3 KB, 17 views)