View Single Post
 
Old 12-18-2018, 08:15 PM
gmaxey gmaxey is offline Windows 10 Office 2016
Expert
 
Join Date: May 2010
Location: Brasstown, NC
Posts: 1,617
gmaxey is just really nicegmaxey is just really nicegmaxey is just really nicegmaxey is just really nicegmaxey is just really nice
Default

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
__________________
Greg Maxey
Please visit my web site at http://www.gregmaxey.com/