Home |
Search |
Today's Posts |
|
#1
![]()
Posted to microsoft.public.word.tables
|
|||
|
|||
![]()
I saw some other questions regarding conditional formating in Word tables, so
I don't hold out much hope for this. But it seems simple enough that there might be some relatively easy way to do it. Here's the situation: In a cell in the top row of a table in my Word template, only 3 values are possible to select using a control: Green, Yellow, Red. Can I make Word change the cell fill color based on the option selected? I tried using an embedded Excel table, but it just doesn't seem to be the right solution in this case, and my manager doesn't want to use Excel for the whole document as I suggested. Thanks |
#2
![]()
Posted to microsoft.public.word.tables
|
|||
|
|||
![]()
If you use legacy form fields in your document, as suggested by Doug in
response to your other query, and one of those fields is a dropdown fiild containing the three values, then you can certainly format a cell of the table based on the selected content of that dropdown field by running a macro on exit from the field. The following, for example, will colour the first cell of the table .Cell(1, 1) according to the result of the field Sub ColorCellA1() Dim sColor As String Dim bProtected As Boolean With ActiveDocument If .ProtectionType wdNoProtection Then bProtected = True .Unprotect Password:="" End If With .Tables(1).Cell(1, 1).Shading Select Case LCase(ActiveDocument.FormFields("Dropdown1").Resul t) Case Is = "red" .BackgroundPatternColor = wdColorRed Case Is = "yellow" .BackgroundPatternColor = wdColorYellow Case Is = "green" .BackgroundPatternColor = wdColorGreen End Select End With If bProtected = True Then .Protect _ Type:=wdAllowOnlyFormFields, _ NoReset:=True, _ Password:="" End If End With End Sub You may find the examples at http://www.gmayor.com/word_vba_examples.htm and http://www.gmayor.com/SelectFile.htm useful. -- Graham Mayor - Word MVP My web site www.gmayor.com Word MVP web site http://word.mvps.org WillW wrote: I saw some other questions regarding conditional formating in Word tables, so I don't hold out much hope for this. But it seems simple enough that there might be some relatively easy way to do it. Here's the situation: In a cell in the top row of a table in my Word template, only 3 values are possible to select using a control: Green, Yellow, Red. Can I make Word change the cell fill color based on the option selected? I tried using an embedded Excel table, but it just doesn't seem to be the right solution in this case, and my manager doesn't want to use Excel for the whole document as I suggested. Thanks |
#3
![]()
Posted to microsoft.public.word.tables
|
|||
|
|||
![]()
Thanks, Graham -- It took me a while to get back to this, but I can see the
possibility of its working. A basic problem for me, though: I can't make the Dropdown1 legacy control function as a dropdown. It just sits there looking grey with no hint of a dropdown. When I step through the macro, the background color changes appropriately (matching the word that happens to be displayed), but I'm not able to select the color from the legacy control. And exiting the control doesn't change the color of A1. What am I doing wrong? (Entering "legacy form control" in Word Help is useless) Thanks "Graham Mayor" wrote: If you use legacy form fields in your document, as suggested by Doug in response to your other query, and one of those fields is a dropdown fiild containing the three values, then you can certainly format a cell of the table based on the selected content of that dropdown field by running a macro on exit from the field. The following, for example, will colour the first cell of the table .Cell(1, 1) according to the result of the field Sub ColorCellA1() Dim sColor As String Dim bProtected As Boolean With ActiveDocument If .ProtectionType wdNoProtection Then bProtected = True .Unprotect Password:="" End If With .Tables(1).Cell(1, 1).Shading Select Case LCase(ActiveDocument.FormFields("Dropdown1").Resul t) Case Is = "red" .BackgroundPatternColor = wdColorRed Case Is = "yellow" .BackgroundPatternColor = wdColorYellow Case Is = "green" .BackgroundPatternColor = wdColorGreen End Select End With If bProtected = True Then .Protect _ Type:=wdAllowOnlyFormFields, _ NoReset:=True, _ Password:="" End If End With End Sub You may find the examples at http://www.gmayor.com/word_vba_examples.htm and http://www.gmayor.com/SelectFile.htm useful. -- Graham Mayor - Word MVP My web site www.gmayor.com Word MVP web site http://word.mvps.org WillW wrote: I saw some other questions regarding conditional formating in Word tables, so I don't hold out much hope for this. But it seems simple enough that there might be some relatively easy way to do it. Here's the situation: In a cell in the top row of a table in my Word template, only 3 values are possible to select using a control: Green, Yellow, Red. Can I make Word change the cell fill color based on the option selected? I tried using an embedded Excel table, but it just doesn't seem to be the right solution in this case, and my manager doesn't want to use Excel for the whole document as I suggested. Thanks |
#4
![]()
Posted to microsoft.public.word.tables
|
|||
|
|||
![]()
You have to protect the document for forms for legacy fields to work.
You should find http://gregmaxey.mvps.org/Classic%20Form%20Controls.htm useful. -- Graham Mayor - Word MVP My web site www.gmayor.com Word MVP web site http://word.mvps.org WillW wrote: Thanks, Graham -- It took me a while to get back to this, but I can see the possibility of its working. A basic problem for me, though: I can't make the Dropdown1 legacy control function as a dropdown. It just sits there looking grey with no hint of a dropdown. When I step through the macro, the background color changes appropriately (matching the word that happens to be displayed), but I'm not able to select the color from the legacy control. And exiting the control doesn't change the color of A1. What am I doing wrong? (Entering "legacy form control" in Word Help is useless) Thanks "Graham Mayor" wrote: If you use legacy form fields in your document, as suggested by Doug in response to your other query, and one of those fields is a dropdown fiild containing the three values, then you can certainly format a cell of the table based on the selected content of that dropdown field by running a macro on exit from the field. The following, for example, will colour the first cell of the table .Cell(1, 1) according to the result of the field Sub ColorCellA1() Dim sColor As String Dim bProtected As Boolean With ActiveDocument If .ProtectionType wdNoProtection Then bProtected = True .Unprotect Password:="" End If With .Tables(1).Cell(1, 1).Shading Select Case LCase(ActiveDocument.FormFields("Dropdown1").Resul t) Case Is = "red" .BackgroundPatternColor = wdColorRed Case Is = "yellow" .BackgroundPatternColor = wdColorYellow Case Is = "green" .BackgroundPatternColor = wdColorGreen End Select End With If bProtected = True Then .Protect _ Type:=wdAllowOnlyFormFields, _ NoReset:=True, _ Password:="" End If End With End Sub You may find the examples at http://www.gmayor.com/word_vba_examples.htm and http://www.gmayor.com/SelectFile.htm useful. -- Graham Mayor - Word MVP My web site www.gmayor.com Word MVP web site http://word.mvps.org WillW wrote: I saw some other questions regarding conditional formating in Word tables, so I don't hold out much hope for this. But it seems simple enough that there might be some relatively easy way to do it. Here's the situation: In a cell in the top row of a table in my Word template, only 3 values are possible to select using a control: Green, Yellow, Red. Can I make Word change the cell fill color based on the option selected? I tried using an embedded Excel table, but it just doesn't seem to be the right solution in this case, and my manager doesn't want to use Excel for the whole document as I suggested. Thanks |
#5
![]()
Posted to microsoft.public.word.tables
|
|||
|
|||
![]()
Want to hold my hand through one more step? Everything seems to work in its
parts. The legacy dropdown is located in cell (1,4) of the first table on the page (there are others lower on the page). I changed the cell reference in the macro so the same cell changes color. I stepped through the macro, and it works. I selected the macro to run on Exit (on exiting the dropdown?). I protected the form and saved it as a .dotm. But the macro is not triggered when I move from the control (to verify, I set a break point). Thinking it might be a macro security issue, I "enabled all macros". More help please. "Graham Mayor" wrote: You have to protect the document for forms for legacy fields to work. You should find http://gregmaxey.mvps.org/Classic%20Form%20Controls.htm useful. -- Graham Mayor - Word MVP My web site www.gmayor.com Word MVP web site http://word.mvps.org WillW wrote: Thanks, Graham -- It took me a while to get back to this, but I can see the possibility of its working. A basic problem for me, though: I can't make the Dropdown1 legacy control function as a dropdown. It just sits there looking grey with no hint of a dropdown. When I step through the macro, the background color changes appropriately (matching the word that happens to be displayed), but I'm not able to select the color from the legacy control. And exiting the control doesn't change the color of A1. What am I doing wrong? (Entering "legacy form control" in Word Help is useless) Thanks "Graham Mayor" wrote: If you use legacy form fields in your document, as suggested by Doug in response to your other query, and one of those fields is a dropdown fiild containing the three values, then you can certainly format a cell of the table based on the selected content of that dropdown field by running a macro on exit from the field. The following, for example, will colour the first cell of the table .Cell(1, 1) according to the result of the field Sub ColorCellA1() Dim sColor As String Dim bProtected As Boolean With ActiveDocument If .ProtectionType wdNoProtection Then bProtected = True .Unprotect Password:="" End If With .Tables(1).Cell(1, 1).Shading Select Case LCase(ActiveDocument.FormFields("Dropdown1").Resul t) Case Is = "red" .BackgroundPatternColor = wdColorRed Case Is = "yellow" .BackgroundPatternColor = wdColorYellow Case Is = "green" .BackgroundPatternColor = wdColorGreen End Select End With If bProtected = True Then .Protect _ Type:=wdAllowOnlyFormFields, _ NoReset:=True, _ Password:="" End If End With End Sub You may find the examples at http://www.gmayor.com/word_vba_examples.htm and http://www.gmayor.com/SelectFile.htm useful. -- Graham Mayor - Word MVP My web site www.gmayor.com Word MVP web site http://word.mvps.org WillW wrote: I saw some other questions regarding conditional formating in Word tables, so I don't hold out much hope for this. But it seems simple enough that there might be some relatively easy way to do it. Here's the situation: In a cell in the top row of a table in my Word template, only 3 values are possible to select using a control: Green, Yellow, Red. Can I make Word change the cell fill color based on the option selected? I tried using an embedded Excel table, but it just doesn't seem to be the right solution in this case, and my manager doesn't want to use Excel for the whole document as I suggested. Thanks |
Reply |
Thread Tools | |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
"Conditional Formatting" of Word Table Cell | Tables | |||
How do I change a table cell color globally? | Tables | |||
Word 2007 table cell color selection | Tables | |||
Custom Table Style-Background Cell Color | Tables | |||
Need to add fill color to a table cell | Tables |