Paul,
Not very elegant but one may have to deal with merged cells:
Code:
Private Sub Document_ContentControlOnExit(ByVal ContentControl As ContentControl, Cancel As Boolean)
With ContentControl
If Len(.Title) < 6 Then Exit Sub
If Left(.Title, 6) = "Status" Then
On Error GoTo Err_Merged
Select Case .Range.Text
Case "COMPLETE"
.Range.Rows(1).Shading.BackgroundPatternColorIndex = wdGreen
Case "Pending": .Range.Rows(1).Shading.BackgroundPatternColorIndex = wdYellow
Case Else: .Range.Rows(1).Shading.BackgroundPatternColorIndex = wdNoHighlight
End Select
End If
End With
lbl_Exit:
Exit Sub
Err_Merged:
DealWithMergedCells ContentControl
End Sub
Sub DealWithMergedCells(oCC As ContentControl)
Dim oCellRef As Cell, oCell As Cell
Set oCellRef = oCC.Range.Cells(1)
Select Case oCC.Range.Text
Case "COMPLETE"
oCC.Range.Cells(1).Shading.BackgroundPatternColorIndex = wdGreen
Case "Pending"
oCC.Range.Cells(1).Shading.BackgroundPatternColorIndex = wdYellow
Case Else
oCC.Range.Cells(1).Shading.BackgroundPatternColorIndex = wdNoHighlight
End Select
For Each oCell In oCC.Range.Tables(1).Range.Cells
If oCell.RowIndex = oCellRef.RowIndex Then
oCell.Shading.BackgroundPatternColorIndex = oCC.Range.Cells(1).Shading.BackgroundPatternColorIndex
End If
Next
End Sub