Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 06-11-2018, 01:42 AM
gsbpxw gsbpxw is offline Code to change highlight on content control automatically Windows 7 32bit Code to change highlight on content control automatically Office 2010 32bit
Novice
Code to change highlight on content control automatically
 
Join Date: Jun 2018
Posts: 3
gsbpxw is on a distinguished road
Default 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
Reply With Quote
  #2  
Old 06-11-2018, 02:47 AM
Guessed's Avatar
Guessed Guessed is online now Code to change highlight on content control automatically Windows 10 Code to change highlight on content control automatically Office 2016
Expert
 
Join Date: Mar 2010
Location: Canberra/Melbourne Australia
Posts: 3,966
Guessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant future
Default

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
Reply With Quote
  #3  
Old 06-11-2018, 03:05 AM
gsbpxw gsbpxw is offline Code to change highlight on content control automatically Windows 7 32bit Code to change highlight on content control automatically Office 2010 32bit
Novice
Code to change highlight on content control automatically
 
Join Date: Jun 2018
Posts: 3
gsbpxw is on a distinguished road
Talking

Thank you!!

Works perfectly
Reply With Quote
Reply

Tags
content control, vba change colour

Thread Tools
Display Modes


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
Code to change highlight on content control automatically 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 change highlight on content control automatically 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
Code to change highlight on content control automatically Deleting a table from a content control -- preserving the content control BrainSlugs83 Word Tables 8 11-14-2013 03:06 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 04:03 PM.


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