![]() |
|
#1
|
|||
|
|||
|
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
|
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
Change color according with dropdown selection
|
spk | Word VBA | 43 | 07-31-2022 03:51 PM |
Dropdown dependencies with multiple dropdowns
|
LaurenM | Word VBA | 9 | 11-22-2017 11:46 PM |
Dropdown selection value
|
coconutt | Word VBA | 5 | 09-13-2012 05:23 PM |
Change cell color when selection is made from a drop down list
|
fedcco | Excel | 12 | 08-28-2012 10:43 PM |
| Change cell color everytime a value is selected in dropdown list | angelica_gloria | Excel | 4 | 01-27-2012 06:47 PM |