Consulting

Results 1 to 8 of 8

Thread: Conditional Format of Word Content Control Drop down box

  1. #1

    Conditional Format of Word Content Control Drop down box

    I am creating a Word form in Word 2010. I have created a drop down box to indicate the status of a project. There are three options, Red, Yellow, And Green. I would like to format the drop down box so that its background colour will correspond with the choice.
    Thank you in advance.
    Scotto

  2. #2
    Knowledge Base Approver VBAX Guru macropod's Avatar
    Joined
    Jul 2008
    Posts
    3,944
    Location
    It's not clear whether you want to colour the: (a) content control's background; (b) font; or, perhaps (c) table cell that the content control is in.

    For a:
    Private Sub Document_ContentControlOnExit(ByVal ContentControl As ContentControl, Cancel As Boolean)
    With ContentControl
      If .Title = "Risk" Then
        Select Case .Range.Text
          Case "High": .Range.Font.ColorIndex = wdRed
          Case "Medium": .Range.Font.ColorIndex = wdYellow
          Case "Low": .Range.Font.ColorIndex = wdBrightGreen
          Case Else: .Range.Font.ColorIndex = wdAuto
        End Select
      End If
    End With
    End Sub
    For b:
    Private Sub Document_ContentControlOnExit(ByVal ContentControl As ContentControl, Cancel As Boolean)
    With ContentControl
      If .Title = "Risk" Then
        Select Case .Range.Text
          Case "High": .Range.Shading.BackgroundPatternColorIndex = wdRed
          Case "Medium": .Range.Shading.BackgroundPatternColorIndex = wdYellow
          Case "Low": .Range.Shading.BackgroundPatternColorIndex = wdBrightGreen
          Case Else: .Range.Shading.BackgroundPatternColorIndex = wdNoHighlight
        End Select
      End If
    End With
    End Sub
    For c:
    Private Sub Document_ContentControlOnExit(ByVal ContentControl As ContentControl, Cancel As Boolean)
    With ContentControl
       If .Title = "Risk" Then
        Select Case .Range.Text
          Case "High": .Range.Cells(1).Shading.BackgroundPatternColorIndex = wdRed
          Case "Medium": .Range.Cells(1).Shading.BackgroundPatternColorIndex = wdYellow
          Case "Low": .Range.Cells(1).Shading.BackgroundPatternColorIndex = wdBrightGreen
          Case Else: .Range.Cells(1).Shading.BackgroundPatternColorIndex = wdNoHighlight
        End Select
        End If
    End With
    End Sub
    Whichever version you want to use should be saved to the 'ThisDocument' code module of the document or it's template. The file will need to be saved as a macro-enabled file (dotm template or docm document). It's also possible to combine changes in font colour & background shading.
    Cheers
    Paul Edstein
    [Fmr MS MVP - Word]

  3. #3

    It works!

    I have just tried your code and it worked very well. Thank you very much for the speedy reponse!
    Scotto

  4. #4
    VBAX Newbie
    Joined
    Mar 2019
    Posts
    3
    Location

    White background w/colour font change only on selection

    I tried all 3of these codes to try and adapt to my needs. I failed. Can you help me to change the font color only when a drop down is selected? I have 2 selections in my drop down, "yes" is a red Font and no is black. The above codes change the cell colors not just the font. Thank you very much!
    Last edited by macropod; 03-22-2019 at 02:32 PM. Reason: Deleted unnecessary quote of entire post replied to

  5. #5
    Knowledge Base Approver VBAX Guru macropod's Avatar
    Joined
    Jul 2008
    Posts
    3,944
    Location
    Quote Originally Posted by Lin View Post
    I tried all 3of these codes …
    The above codes change the cell colors not just the font.
    That simply isn't so. The:
    • first colours only the text;
    • second colours only the content control background;
    • third
    colours the content control's cell.
    None of the codes changes both the font colour and the background colour.
    Cheers
    Paul Edstein
    [Fmr MS MVP - Word]

  6. #6
    VBAX Newbie
    Joined
    Mar 2019
    Posts
    3
    Location
    Thank you so much! I finally got it to work for me. I'm a newbie so please excuse me. I have another problem that maybe you can advise me on...I am unable to send the attachment with the VBA code on it to colleagues so they can use it. It flags a Malware error and won't send or receive. Iam using Outlook 365 email at work. Any suggestions on how to save/send so I will work. Thank you so much!

  7. #7
    Knowledge Base Approver VBAX Guru macropod's Avatar
    Joined
    Jul 2008
    Posts
    3,944
    Location
    Whatever your email problem is, it has nothing to do with the subject matter of this thread. I suggest you start a new thread in the appropriate forum.
    Cheers
    Paul Edstein
    [Fmr MS MVP - Word]

  8. #8
    VBAX Newbie
    Joined
    Mar 2019
    Posts
    3
    Location

    Thank you

    Quote Originally Posted by macropod View Post
    Whatever your email problem is, it has nothing to do with the subject matter of this thread. I suggest you start a new thread in the appropriate forum.
    I apologize...I will if I can figure it out. Thank you! Have a good evening!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •