View Single Post
 
Old 09-24-2021, 01:26 AM
TheAnimal TheAnimal is offline Windows XP Office 2019
Novice
 
Join Date: Sep 2021
Posts: 4
TheAnimal is on a distinguished road
Default Apply 2 VBA codes to a single content control drop down

Hi, complete noob here
Please can I get some advice with applying two VBA codes to a single content control drop down box.
I've managed to get them to work individually but not sure how to apply both simultaneously.
I have a drop down with 3 options: Red, Amber or Green, which turn the corresponding colour on exit. I also want the value to populate as opposed to the display name.
A huge thank you to Greg Maxey and Paul Edstein who's website and previous answers to threads have got me this far!

Code currently as follows:

Private Sub Document_ContentControlOnExit(ByVal CC As ContentControl, Cancel As Boolean)
Dim lngIndex As Long
Dim strValue As String
Select Case CC.Title
Case "RAG"
If CC.ShowingPlaceholderText Then Exit Sub
With CC
If .Title = "RAG" Then
Select Case .Range.Text
Case "RED": .Range.Font.Color = RGB(178, 34, 34)
Case "AMBER": .Range.Font.Color = RGB(255, 165, 0)
Case "GREEN": .Range.Font.Color = RGB(50, 205, 50)
Case Else: .Range.Font.ColorIndex = wdAuto
For lngIndex = 2 To .DropdownListEntries.Count
If .DropdownListEntries(lngIndex).Text = .Range.Text Then
strValue = .DropdownListEntries(lngIndex).Value
.Type = wdContentControlText
.Range.Text = strValue
.Type = wdContentControlDropdownList
Exit For
End If
Next lngIndex
End With
Case Else
End Select
lbl_Exit:
Exit Sub
End Sub

Private Sub Document_ContentControlOnExit(ByVal ContentControl As ContentControl, Cancel As Boolean)
With ContentControl
If .Title = "RAG" Then
Select Case .Range.Text
Case "RED": .Range.Font.Color = RGB(178, 34, 34)
Case "AMBER": .Range.Font.Color = RGB(255, 165, 0)
Case "GREEN": .Range.Font.Color = RGB(50, 205, 50)
Case Else: .Range.Font.ColorIndex = wdAuto
End Select

How can I combine these to perform both instructions??

Thank you and please be aware that I already know how incompetent I am with VBA
Reply With Quote