0
votes

Currently I have a macro that change the .BackgroundPatternColor based on the Drop-Down List Content Control value selected. It applies to the entire table cell.

Code below + screenshot how it looks.

Private Sub Document_ContentControlOnExit(ByVal ContentControl As ContentControl, Cancel As Boolean)
With ContentControl.Range
    If ContentControl.Title = "Status" Then
        Select Case .Text
            Case "RED"
                .Cells(1).Shading.BackgroundPatternColor = RGB(227, 36, 27)
                .Cells(1).Range.Font.TextColor = wdColorWhite
            Case "AMBER"
                .Cells(1).Shading.BackgroundPatternColor = RGB(251, 171, 24)
                .Cells(1).Range.Font.TextColor = wdColorBlack
            Case "GREEN"
                .Cells(1).Shading.BackgroundPatternColor = RGB(110, 190, 74)
                .Cells(1).Range.Font.TextColor = wdColorWhite
            Case Else
                .Cells(1).Shading.BackgroundPatternColor = wdColorAutomatic
        End Select
    End If
End With
End Sub

enter image description here

Since you can't change the Text Highlight Color in MS Word via VBA I have discovered I can achieve desired look by changing Style format of Content Control in Properties.

Properties -> +NewStyle -> Format -> Border...

enter image description here

enter image description here

Only then I get my desired "highlighting text" look with custom coluors, instead of changing the entire background of the table cell.

What I want is something like this:

enter image description here

I have created separate style for each selection type.

enter image description here

However, I can't figure out the way to change the Content Control Properties Text Style's based on the current drop-down value selection in MS Word.

Please help. Thanks

1

1 Answers

0
votes

Perhaps:

Private Sub Document_ContentControlOnExit(ByVal CCtrl As ContentControl, Cancel As Boolean)
With CCtrl
  If .Title = "Status" Then
    With .Range
      Select Case .Text
        Case "RED"
          .Shading.BackgroundPatternColorIndex = wdRed
          .Font.ColorIndex = wdWhite
        Case "AMBER"
          .Shading.BackgroundPatternColorIndex = wdDarkYellow
          .Font.ColorIndex = wdColorBlack
        Case "GREEN"
          .Shading.BackgroundPatternColorIndex = wdBrightGreen
          .Font.ColorIndex = wdWhite
        Case Else
          .Shading.BackgroundPatternColorIndex = wdAuto
      End Select
    End With
  End If
End With
End Sub