Microsoft Office Forums

Go Back   Microsoft Office Forums > >

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
  #11  
Old 08-24-2016, 01:39 PM
palmiema palmiema is offline Change color according with dropdown selection Windows 7 64bit Change color according with dropdown selection Office 2010 64bit
Novice
 
Join Date: Aug 2016
Posts: 10
palmiema is on a distinguished road
Default

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

Last edited by macropod; 09-10-2018 at 02:50 PM. Reason: Added code tags & formatting
 

Tags
color, dropdown, reaction



Similar Threads
Thread Thread Starter Forum Replies Last Post
block selection in dropdown list Intruder Excel 2 01-10-2013 10:20 AM
Change color according with dropdown selection Dropdown selection value coconutt Word VBA 5 09-13-2012 05:23 PM
Change color according with dropdown selection Change cell color when selection is made from a drop down list fedcco Excel 12 08-28-2012 10:43 PM
Change color according with dropdown selection Autofill a form which is contingent on a dropdown selection. biffle0764 Word 2 05-09-2012 12:54 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 03:00 PM.


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