View Single Post
 
Old 08-22-2023, 04:53 PM
Guessed's Avatar
Guessed Guessed is offline Windows 10 Office 2016
Expert
 
Join Date: Mar 2010
Location: Canberra/Melbourne Australia
Posts: 4,176
Guessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant future
Default

I'm not seeing your experience with the second CC also getting the colour applied. I can click from CC to CC without the second one also being recoloured. Try this modification on your code
Code:
Private Sub Document_ContentControlOnExit(ByVal CC As ContentControl, Cancel As Boolean)
  Dim iCol As Long
  iCol = wdBlack    'set default colour
  If Not CC.ShowingPlaceholderText Then
    If CC.Title = "Question1" Then
      Select Case CC.Range.Text
        Case "1": iCol = wdGreen
        Case Else: iCol = wdRed
      End Select
    ElseIf CC.Title = "Question2" Then
      Select Case CC.Range.Text
        Case "High": iCol = wdGreen
        'Case "Medium": iCol = wdBlack
        Case "Low": iCol = wdRed
      End Select
    End If
    CC.Range.Font.ColorIndex = iCol
  End If
End Sub
I think you are out of luck with seeing the colour change before you leave the CC. There is an event that kicks off with the CC change IF the CC is mapped to an XML element. However, when I try to recolour the text in the CC I get a message to say "This object model command is not available while in the current element". You could experiment with it yourself by mapping the CC to XML and adding a Document_ContentControlBeforeStoreUpdate macro to the module
__________________
Andrew Lockton
Chrysalis Design, Melbourne Australia
Reply With Quote