Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 12-18-2017, 03:18 PM
UghMacro UghMacro is offline Change color according with dropdown selection - two different dropdowns Windows 7 64bit Change color according with dropdown selection - two different dropdowns Office 2010 64bit
Novice
Change color according with dropdown selection - two different dropdowns
 
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, 12 views)
Reply With Quote
  #2  
Old 12-18-2017, 04:30 PM
macropod's Avatar
macropod macropod is offline Change color according with dropdown selection - two different dropdowns Windows 7 64bit Change color according with dropdown selection - two different dropdowns Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,956
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

See: https://www.msofficeforums.com/word-...html#post47254

As for your code (which isn't what you have in the attachment), a test like:
If Left(.Title, 4) = "Severity" Then
will never work, since "Severity" has more than 4 characters. There are other errors in your code, too.

Try:
Code:
Private Sub Document_ContentControlOnExit(ByVal ContentControl As ContentControl, Cancel As Boolean)
With ContentControl
  If .Title = "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
 ElseIf .Title = "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
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
Reply

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
Change color according with dropdown selection - two different dropdowns Change color according with dropdown selection spk Word VBA 43 07-31-2022 03:51 PM
Change color according with dropdown selection - two different dropdowns Dropdown dependencies with multiple dropdowns LaurenM Word VBA 9 11-22-2017 11:46 PM
Change color according with dropdown selection - two different dropdowns Dropdown selection value coconutt Word VBA 5 09-13-2012 05:23 PM
Change color according with dropdown selection - two different dropdowns 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

Other Forums: Access Forums

All times are GMT -7. The time now is 08:38 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2024 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft