View Single Post
 
Old 02-15-2023, 10:15 PM
gmayor's Avatar
gmayor gmayor is offline Windows 10 Office 2019
Expert
 
Join Date: Aug 2014
Posts: 4,144
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

If you want to write the associated text to one control, the code is simpler
Code:
Private Sub Document_ContentControlOnExit(ByVal ContentControl As ContentControl, Cancel As Boolean)
Dim oRng As Range
    sNul = ChrW(8203)
    Set oRng = ActiveDocument.SelectContentControlsByTitle("Text 1").Item(1).Range
    If ContentControl.Title = "Combo1" Then
        If ContentControl.ShowingPlaceholderText = False Then
            Select Case Trim(ContentControl.Range.Text)
                Case "BCA_DCC"
                    oRng.Text = "Paragraph 1" & vbCr & "Paragraph 3"
                Case "BCA_NODCC"
                    oRng.Text = "Paragraph 2"
                Case "SOA_DCC"
                    oRng.Text = "Paragraph 3"
                Case "SOA_NODCC"
                    oRng.Text = "Paragraph 4"
                Case Else
                    oRng.Text = ""
            End Select
        End If
    End If
End Sub
If you want to write different texts to two or more controls then you can do that also
Code:
Private Sub Document_ContentControlOnExit(ByVal ContentControl As ContentControl, Cancel As Boolean)
Dim oRng1 As Range, oRng2 As Range
    sNul = ChrW(8203)
    Set oRng1 = ActiveDocument.SelectContentControlsByTitle("Text 1").Item(1).Range
    Set oRng2 = ActiveDocument.SelectContentControlsByTitle("Text 2").Item(1).Range

    If ContentControl.Title = "Combo1" Then
        If ContentControl.ShowingPlaceholderText = False Then
            Select Case Trim(ContentControl.Range.Text)
                Case "BCA_DCC"
                    oRng1.Text = "Paragraph 1" & vbCr & "Paragraph 3"
                    oRng2.Text = sNul
                Case "BCA_NODCC"
                    oRng1.Text = "Paragraph 2"
                    oRng2.Text = "Paragraph 4"
                Case "SOA_DCC"
                    oRng1.Text = "Paragraph 3"
                    oRng2.Text = sNul
                Case "SOA_NODCC"
                    oRng1.Text = "Paragraph 4"
                    oRng2.Text = sNul
                Case Else
                    oRng1.Text = ""
                    oRng2.Text = ""
            End Select
        End If
    End If
End Sub
What you can't do is make multiple selections in a combo box. If you want to make multiple selections you need a userform with a list box. You can find how to do that on my web site.
__________________
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