View Single Post
 
Old 08-02-2021, 11:21 PM
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

You can use case statements to identify the control and process accordingly. Note that both your examples populate contentcontrols(2), which seems improbable. Call the controls to be populated by their tags e.g. as follows.
You may find https://www.gmayor.com/insert_content_control_addin.htm useful


Code:
Option Explicit

Private Sub Document_ContentControlOnExit(ByVal ContentControl As ContentControl, Cancel As Boolean)
Dim i As Long
Dim strDetails As String
Dim oCC As ContentControl
    With ContentControl
        If .ShowingPlaceholderText = False Then
            Select Case .Tag
                Case Is = "ProjectManager"
                    For i = 1 To .DropdownListEntries.Count
                        If .DropdownListEntries(i).Text = .Range.Text Then
                            strDetails = Replace(.DropdownListEntries(i).Value, "|", Chr(11))
                            Exit For
                        End If
                    Next i
                    Set oCC = ActiveDocument.SelectContentControlsByTag("Tag of the project manager details").Item(1)
                    oCC.Range.Text = strDetails
                Case Is = "Engineer"
                    For i = 1 To .DropdownListEntries.Count
                        If .DropdownListEntries(i).Text = .Range.Text Then
                            strDetails = Replace(.DropdownListEntries(i).Value, "|", Chr(11))
                            Exit For
                        End If
                    Next i
                    Set oCC = ActiveDocument.SelectContentControlsByTag("Tag of the engineer details").Item(1)
                    oCC.Range.Text = strDetails
                Case Else
            End Select
        End If
    End With
    Set oCC = Nothing
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