PDA

View Full Version : Solved: Custom Colours for cell backgrounds



FhM
01-19-2009, 08:15 AM
I currently have the following code that shades a tables cell background according to the value in another cell. This code works fine but now I need to change the yellow to an orange which is not a predefined colour.

I have tried messing around with assigning constants &H0066FF
and try to get the function RGB(255,102,0) to apply to something but I seem to be missing something. Can anyone help me out? This seems very basic but I cant quite find the right syntax/formula to get it to work.

TIA

Sub ColourSubjectCells()
Dim oTbl As Table
Dim oRow As Row
Dim oRng As Range
Dim numColumns As Integer
' Dim MyOrange As Long
Const MyOrange = &H66FF
For Each oTbl In ActiveDocument.Tables
numColumns = oTbl.Columns.Count
For Each oRow In oTbl.Rows
Set oRng = oRow.Cells(numColumns).Range
oRng.End = oRng.End - 1
With oRow.Cells(1).Shading
Select Case oRng.Text
Case "r"
.BackgroundPatternColorIndex = wdRed
Case "o"
.BackgroundPatternColorIndex = wdYellow
Case "g"
.BackgroundPatternColorIndex = wdGreen
End Select
End With
Next
oTbl.Columns(numColumns).Delete

Next

End Sub

TonyJollans
01-19-2009, 10:29 AM
You must set BackgroundPatternColor instead of BackgroundPatternColorIndex

FhM
01-20-2009, 03:12 AM
Thanks I knew it would be something straight forward. :friends: