View Single Post
 
Old 12-18-2017, 03:18 PM
UghMacro UghMacro is offline Windows 7 64bit Office 2010 64bit
Novice
 
Join Date: Dec 2017
Posts: 1
UghMacro is on a distinguished road
Default Change color according with dropdown selection - two different dropdowns

I have a template with two dropdown menus. I need the background color of each to change based on the choice. The first dropdown is called "Risk" and the second is called "severity". I used the code suggested by macropod in previous posts and it works great. However, I need "severity" to do the same thing but also change the text so that it can not be seen. The Titles of the choices are as follows:
R=Red
DR=DarkRed
Y=Yellow
G=Green
BG=BrightGreen
I have tried variations of this code and have not gotten Severity to work. I came up with the code below. Not sure how to proceed and have both work.

Code:
Option Explicit

Private Sub Document_ContentControlOnExit(ByVal ContentControl As ContentControl, Cancel As Boolean)
With ContentControl
  If Len(.Title) < 4 Then Exit Sub
  If Left(.Title, 4) = "Risk" Then
    Select Case .Range.Text
      Case "High": .Range.Cells(1).Shading.BackgroundPatternColorIndex = wdRed
      Case "Moderate": .Range.Cells(1).Shading.BackgroundPatternColor = RGB(255, 192, 0)
      Case "Critical": .Range.Cells(1).Shading.BackgroundPatternColor = RGB(192, 0, 0)
      Case Else: .Range.Cells(1).Shading.BackgroundPatternColorIndex = wdNoHighlight
    End Select
 If Left(.Title, 4) = "Severity" Then
    Select Case .Range.Text
      Case "R": .Range.Cells(1).Shading.BackgroundPatternColorIndex = wdRed
                     .Range.Cells(1).Range.Font.Color = wdRed
      Case "Y": .Range.Cells(1).Shading.BackgroundPatternColor = RGB(255, 192, 0)
                     .Range.Cells(1).Range.Font.Color = RGB(255, 192, 0)
      Case "DR": .Range.Cells(1).Shading.BackgroundPatternColor = RGB(192, 0, 0)
                       .Range.Cells(1).Range.Font.Color = RGB(192, 0, 0)
      Case "G".Range.Cells(1).Shading.BackgroundPatternColor = wdGreen 
                   .Range.Cells(1).Range.Font.Color = wdGreen 
      Case "BG".Range.Cells(1).Shading.BackgroundPatternColor = wdBrightGreen 
                    .Range.Cells(1).Range.Font.Color = wdBrightGreen 
      Case Else: .Range.Cells(1).Shading.BackgroundPatternColorIndex = wdNoHighlight
    End Select
  End If
End With
End Sub
Attached Files
File Type: docm TableColors.docm (58.3 KB, 15 views)
Reply With Quote