Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 08-22-2023, 07:51 AM
Pbennett71 Pbennett71 is offline Previous font color carries over to selections in next Content Control Drop-down list selection Windows 10 Previous font color carries over to selections in next Content Control Drop-down list selection Office 2021
Novice
Previous font color carries over to selections in next Content Control Drop-down list selection
 
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
  #2  
Old 08-22-2023, 04:53 PM
Guessed's Avatar
Guessed Guessed is offline Previous font color carries over to selections in next Content Control Drop-down list selection Windows 10 Previous font color carries over to selections in next Content Control Drop-down list selection Office 2016
Expert
 
Join Date: Mar 2010
Location: Canberra/Melbourne Australia
Posts: 3,977
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
Reply

Tags
drop-down list, font color



Similar Threads
Thread Thread Starter Forum Replies Last Post
font color based on content control pulldown selection PbFoot Word VBA 3 01-03-2023 08:22 AM
Lock or unlock a content control depending on the selection from the drop down list ncruz Word VBA 4 10-15-2021 08:50 AM
Content control font color rkferguson Word VBA 1 12-18-2018 05:06 AM
Table with content control drop down - change font DebA Word 3 04-29-2018 09:07 PM
Previous font color carries over to selections in next Content Control Drop-down list selection Change cell color when selection is made from a drop down list fedcco Excel 12 08-28-2012 10:43 PM

Other Forums: Access Forums

All times are GMT -7. The time now is 09:09 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2024 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft