View Single Post
 
Old 08-22-2023, 07:51 AM
Pbennett71 Pbennett71 is offline Windows 10 Office 2021
Novice
 
Join Date: Aug 2023
Posts: 5
Pbennett71 is on a distinguished road
Default Previous font color carries over to selections in next Content Control Drop-down list selection

I'm very new to VBA...

I have several content control drop-down lists in my document. I have written the below VB to change the color of the font based on the selection from the drop-down lists.

Private Sub Document_ContentControlOnExit(ByVal CC As ContentControl, Cancel As Boolean)


If CC.Title = "Question1" And Not CC.ShowingPlaceholderText Then
Select Case CC.Range.Text
Case "1": CC.Range.Font.ColorIndex = wdGreen
Case Is <> "1": CC.Range.Font.ColorIndex = wdRed
End Select
End If

If CC.Title = "Question2" And Not CC.ShowingPlaceholderText Then
Select Case CC.Range.Text
Case "High": CC.Range.Font.ColorIndex = wdGreen
Case "Medium": CC.Range.Font.ColorIndex = wdBlack
Case "Low": CC.Range.Font.ColorIndex = wdRed
End Select
End If
End Sub


For Question1, if the user selects "1" from the drop-down list, the 1 will turn green when exiting the the Content Control. Any other response will turn red.

My problem is that when a selection is "clicked on" in the next content-control drop-down list, the font color of the selection changes to the color of the previous selection until the user exits that content control, then it changes to the appropriate color.

I'm looking for a way to prevent the font color from carrying over from one content control drop-down list to another.

As an added bonus, I'd like for the selection to change font color when the selection is made prior to exiting the content control.

Any assistance would be appreciated.
Reply With Quote