Assigning Color

D

Dmitry Osipov

Is there a way to assign a specific color to a table cell, depending on the
value of the merge field? Say, my UserType field can be of five possible
values and I want to color code the table cell that contains this field.
Appreciate any help.
 
G

Greg

The following macro looks at the cell at row 1, column 1 and shades the
cell based on a text value. You might adapt it to your needs:

Sub Test()
Dim oTbl As Word.Table
For Each oTbl In ActiveDocument.Tables
MsgBox oTbl.Cell(1, 1).Range.Text
Select Case Left(oTbl.Cell(1, 1).Range.Text, Len(oTbl.Cell(1,
1).Range.Text) - 2)
Case "Apples"
oTbl.Cell(1, 1).Shading.BackgroundPatternColorIndex = wdRed
Case "Lemons"
oTbl.Cell(1, 1).Shading.BackgroundPatternColorIndex = wdYellow
Case Else
'Continue case statements up to Case "5" as appropriate
End Select
Next
End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top