#1
|
|||
|
|||
Code to change highlight on content control automatically
I have code which will change the colour on a content control drop down when the macro isrun, but I would like it to run automatically when I exit the content control, please could you advise?
Sub AddColour() Dim cc1 As ContentControl Set cc1 = ActiveDocument.SelectContentControlsByTitle("Ratin g").Item(1) If cc1.Title = "Rating" Then Select Case True Case cc1.Range.Text = "Feasible" cc1.Range.Shading.BackgroundPatternColor = wdColorGreen Case cc1.Range.Text = "Less Feasible" cc1.Range.Shading.BackgroundPatternColor = wdColorYellow Case cc1.Range.Text = "Not Feasible" cc1.Range.Shading.BackgroundPatternColor = wdColorRed Case Else cc1.Range.Shading.BackgroundPatternColor = wdColorAutomatic End Select End If End Sub |
#2
|
||||
|
||||
Try this macro. It needs to be placed in the ThisDocument module
Code:
Private Sub Document_ContentControlOnExit(ByVal aCC As ContentControl, Cancel As Boolean) Dim dblColour As Double If aCC.Title = "Rating" Then Select Case aCC.Range.Text Case "Feasible" dblColour = wdColorGreen Case "Less Feasible" dblColour = wdColorYellow Case "Not Feasible" dblColour = wdColorRed Case Else dblColour = wdColorAutomatic End Select aCC.Range.Shading.BackgroundPatternColor = dblColour End If End Sub
__________________
Andrew Lockton Chrysalis Design, Melbourne Australia |
#3
|
|||
|
|||
Thank you!!
Works perfectly |
Tags |
content control, vba change colour |
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
Table with content control drop down - change font | DebA | Word | 3 | 04-29-2018 09:07 PM |
Is there a way to anchor drop-down content control boxes so entering text doesn't change formatting? | TzarChasm | Word | 7 | 04-14-2016 06:28 PM |
Code to Sum Column of Content Control Values In Specific Tables? | warbird | Word VBA | 2 | 07-13-2015 05:44 AM |
a code that can change the layout for the headers and footers on each page automatically | gmbh | Word VBA | 1 | 07-31-2014 04:24 AM |
Deleting a table from a content control -- preserving the content control | BrainSlugs83 | Word Tables | 8 | 11-14-2013 03:06 AM |