Re: Setting color of table cell based on list selection
- From: Jay Freedman <jay.freedman@xxxxxxxxxxx>
- Date: Sun, 29 Mar 2009 00:03:48 -0400
Your reference to a tag and the lack of results from the CheckFormFields macro
indicate that the "drop down fields" you used are actually content controls and
not formfields. That's why there are no members of the FormFields collection.
Either you can replace those content controls with dropdown formfields from the
Legacy Tools button (fourth from the left in the second row of the Controls
group), or you can change the macro to work with the content controls.
You can't refer to a content control directly by its tag the way you could refer
to a formfield by its bookmark name; instead, you must loop through the
collection until you find one with the desired tag (and note that tags aren't
necessarily unique). The modified code would be
Sub ColorRiskCell()
Dim oCC As ContentControl
With ActiveDocument
For Each oCC In .ContentControls
If oCC.Tag = "Risk" Then Exit For
Next
If Not oCC Is Nothing Then
If oCC.Range.Text = "High" Then
.Tables(1).Cell(3, 3).Shading.BackgroundPatternColor _
= wdColorRed
Else
.Tables(1).Cell(3, 3).Shading.BackgroundPatternColor _
= wdColorGreen
End If
End If
End With
End Sub
--
Regards,
Jay Freedman
Microsoft Word MVP FAQ: http://word.mvps.org
Email cannot be acknowledged; please post all follow-ups to the newsgroup so all
may benefit.
On Sat, 28 Mar 2009 19:41:10 -0700 (PDT), Alan <jalanthomas@xxxxxxxxxxx> wrote:
This code should do it, but I am having problems referring to the drop-.
down list I inserted into the table (display shows "Risk Level", tag =
"Risk".
Sub ColorRiskCell()
With ActiveDocument
If .FormFields("Risk").DropDown.Value = "High" Then
ActiveDocument.Tables(1).Cell(3,
3).Shading.BackgroundPatternColor = wdColorRed
Else
ActiveDocument.Tables(1).Cell(3,
3).Shading.BackgroundPatternColor = wdColorGreen
End If
End With
End Sub
So, I tried to print out the names of all the form fields in the
document, but got no output:
Sub CheckFormFields()
Dim aField As FormField
For Each aField In ActiveDocument.FormFields
Debug.Print "Form Field Name: " & aField.Name
Debug.Print "Form Field Type: " & aField.Type
Next aField
End Sub
I cannot use Excel, because this is a form in Word.
So, I am confused. --- Alan
- Follow-Ups:
- References:
- Setting color of table cell based on list selection
- From: Alan
- Re: Setting color of table cell based on list selection
- From: PamC via OfficeKB.com
- Re: Setting color of table cell based on list selection
- From: Alan
- Setting color of table cell based on list selection
- Prev by Date: Re: Word table entries generating inappropriate automatic page breaks
- Next by Date: Re: Controls and Form Fields
- Previous by thread: Re: Setting color of table cell based on list selection
- Next by thread: Re: Setting color of table cell based on list selection
- Index(es):
Relevant Pages
|