#1
|
|||
|
|||
Changing background colour in table based on value.
Hi there,
I am trying to change the color of some cells in a dropdown menu in a table (word document) I am only a fairly average skilled person when it comes to computers and would really appreciate some help. I would like the following to have a green shaded background Independent Supervised I would like the following to have a orange shaded background Assisted I would like the following to have a red shaded background Marginal Dependent I have attached a clip of the table I have in excel to show you what I mean.. It is perfect but i can not get it into a word document. Thank you so much in advance |
#2
|
||||
|
||||
Have a look at this thread
https://www.msofficeforums.com/word-...selection.html
__________________
Andrew Lockton Chrysalis Design, Melbourne Australia |
#3
|
|||
|
|||
Thank you so much, I did try that and it certainly works. How do I go in to change the words and also the yellow colour to orange ?
|
#4
|
||||
|
||||
You need to look closely at the code and adapt it to your requirements. I'm not sure exactly which code you chose. Colours can be explicitly defined in RGB terms for more flexibility in defining a colour.
An example which would give you orange is Code:
Case "Assisted": .Range.Cells(1).Shading.BackgroundPatternColorIndex = RGB(255,192,0)
__________________
Andrew Lockton Chrysalis Design, Melbourne Australia |
#5
|
|||
|
|||
ok thanks... what section do I go into to locate the formula to be able to modify? The code that seemed to work so far is the 'content controls - dropdown conditional formatting.' Thanks again
|
#6
|
||||
|
||||
It appears you are coming from ground zero in terms of using macros. How about you start with this for the basics
Getting to grips with VBA basics in 15 minutes I would also recommend you watch some youtube videos to get an understanding of what is involved in recording, editing and using VBA with Word. https://www.youtube.com/results?sear...Microsoft+Word Once you are comfortable with the VBA Editor and basic coding, the code you are looking for will be in the ThisDocument module of the template.
__________________
Andrew Lockton Chrysalis Design, Melbourne Australia |
#7
|
||||
|
||||
Quote:
For orange, you could use code like: Code:
Const wdOrange As Long = 41215 '... .Cells(1).Shading.BackgroundPatternColor = wdOrange .Font.Color = wdOrange Code:
.Cells(1).Shading.BackgroundPatternColor = wdColorOrange .Font.Color = wdColorOrange
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
#8
|
|||
|
|||
Thanks
Thank you
Yes I am sorry, I did declare I am far from a computer wiz I have attempted a version of both suggestions Version 1 does not change the colour at all and version 2 comes up with an error as attached. I have also attached the document in case it is easier for you to see. I appreciate your time. Amanda |
#9
|
||||
|
||||
You haven't declared the wdOrange constant:
Code:
Const wdOrange As Long = 41215 Code:
Const StrPwd As String = "abc"
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
#10
|
|||
|
|||
Thank you, I have put in the line as you had suggested. The issue I have is that when I use the dropdown menu none of them change the background colour? ie it stays white
it also comes up with the attached error? |
#11
|
||||
|
||||
That End If line needs to move up two lines (after the End With line).
The Title property on your CCs doesn't match the code. Change this line Case "Lst1", "Lst2" to Case "Bondy Scale" Also note that if you are setting the fill and the text colour to exactly the same colour, you won't be able to see the text. Your original request showed the background as a paler tint of the text colour. Once you have the code working, if you want the text to be visible we may need to ensure the background colour is not on 100% fill - but lets get the colour working first.
__________________
Andrew Lockton Chrysalis Design, Melbourne Australia |
#12
|
|||
|
|||
I have made the changes.. still not successful I'm afraid
Thankyou Amanda |
#13
|
|||
|
|||
I would be really just as happy to have the font black and just change the background color to green orange and red if that makes it easier?
|
#14
|
||||
|
||||
Try this code instead. If you want subtle changes in colour to show text on a pastel background you need to use RGB values rather than sticking with limits of the built-in Word variables.
Code:
Private Sub Document_ContentControlOnExit(ByVal ContentControl As ContentControl, Cancel As Boolean) Const StrPwd As String = "abc" With ContentControl Select Case .Title Case "Bondy Scale" If ActiveDocument.ProtectionType <> wdNoProtection Then ActiveDocument.Unprotect Password:=StrPwd With .Range .Cells(1).Shading.Texture = wdTextureNone Select Case .Text Case "Dependent", "Marginal" .Cells(1).Shading.BackgroundPatternColor = RGB(255, 109, 109) .Font.Color = wdColorRed Case "Assisted" .Cells(1).Shading.BackgroundPatternColor = RGB(255, 183, 67) .Font.Color = RGB(255, 160, 0) Case "Supervised", "Independent" .Cells(1).Shading.BackgroundPatternColor = wdColorLightGreen .Font.Color = wdColorBrightGreen Case Else .Cells(1).Shading.BackgroundPatternColor = wdColorWhite .Font.ColorIndex = wdAuto End Select End With ActiveDocument.Protect wdAllowOnlyFormFields, True, StrPwd End Select End With End Sub
__________________
Andrew Lockton Chrysalis Design, Melbourne Australia |
#15
|
|||
|
|||
Thank you
Thank you - that works!! you are amazing!!!
would you help with one last thing please... the table at the top of the document was the original 'Content Controls - Dropdown Conditional Format.docm' however it seems to be protected and i can not delete it from my worksheet. Would you please help me with that? |
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
Background Word Colour not showing on PDF | phorsley | Word | 1 | 04-24-2020 09:18 AM |
Text Background Colour in a Table | Colin Vicary | Word | 4 | 08-08-2019 06:02 AM |
Word background colour ignores Windows setting | wiganken | Word | 1 | 07-19-2018 09:25 AM |
Changing background colour based on dropdown choice | PLeo | Word VBA | 2 | 08-03-2017 07:40 AM |
Trying to clear the background colour from a theme | ezekiel181 | Word | 1 | 11-14-2010 07:29 AM |