View Single Post
 
Old 03-14-2022, 07:01 AM
gmayor's Avatar
gmayor gmayor is offline Windows 10 Office 2019
Expert
 
Join Date: Aug 2014
Posts: 4,138
gmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud of
Default

I think the following will work for the two controls, however it is not clear what .Cells(1) refers to so I have used cell 1 of the first table

Code:
Option Explicit

Private Sub Document_ContentControlOnExit(ByVal CCtrl As ContentControl, Cancel As Boolean)
    Application.ScreenUpdating = False
    Dim i As Long, StrOut As String
    With CCtrl
        If .Title = "Relevans" Then
            Select Case .Range.Text
                Case "Ja"
                    StrOut = "Uakseptabel,Middels,Akseptabel"
                    If CCtrl.Range.Text = "Ja" Then
                        With ActiveDocument.SelectContentControlsByTitle("Risiko")(1)
                            .Type = wdContentControlDropdownList
                            .DropdownListEntries.Clear
                            .Type = wdContentControlRichText
                            .Range.Text = ""
                            .Type = wdContentControlDropdownList
                            For i = 0 To UBound(Split(StrOut, ","))
                                .DropdownListEntries.Add Split(StrOut, ",")(i)
                            Next i
                        End With
                    End If
                Case "Nei"
                    With ActiveDocument.SelectContentControlsByTitle("Risiko")(1)
                        If .Type = wdContentControlDropdownList Then
                            .DropdownListEntries.Clear
                        End If
                        .Type = wdContentControlRichText
                        .Range.Text = "—"
                    End With
                Case Else
                    With ActiveDocument.SelectContentControlsByTitle("Risiko")(1)
                        If .Type = wdContentControlDropdownList Then
                            .DropdownListEntries.Clear
                        End If
                        .Type = wdContentControlRichText
                        .Range.Text = ""
                    End With
            End Select
        End If
    End With
    If CCtrl.Title = "Risiko" Then
        If CCtrl.ShowingPlaceholderText = False Then
            With CCtrl.Range
                Select Case .Text
                    Case "Uakseptabel": ActiveDocument.Tables(1).Range.Cells(1).Shading.BackgroundPatternColor = RGB(255, 0, 0)
                    Case "Akseptabel": ActiveDocument.Tables(1).Range.Cells(1).Shading.BackgroundPatternColor = RGB(0, 176, 80)
                    Case "Middels": ActiveDocument.Tables(1).Range.Cells(1).Shading.BackgroundPatternColor = RGB(255, 255, 0)
                    Case Else: ActiveDocument.Tables(1).Range.Cells(1).Shading.BackgroundPatternColor = wdColorAutomatic
                End Select
            End With
        End If
    End If
End Sub
__________________
Graham Mayor - MS MVP (Word) (2002-2019)
Visit my web site for more programming tips and ready made processes www.gmayor.com
Reply With Quote