View Single Post
 
Old 09-21-2018, 11:25 PM
gmayor's Avatar
gmayor gmayor is offline Windows 10 Office 2016
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 have to actually leave the content control in order for the process below to fire. That means making a selection and clicking outside the control.

Paul's code is explained as follows:
Code:
Private Sub Document_ContentControlOnExit(ByVal CCtrl As ContentControl, Cancel As Boolean)
Dim i As Long    'declare a long variable for use as a counter
With CCtrl    'The content control you are leaving
'check if the content control is in a table. If not quit the process
        If .Range.Information(wdWithInTable) = False Then Exit Sub
        'Ensure only content controls in the first column are processed
        If .Range.Cells(1).ColumnIndex > 1 Then Exit Sub
        'Process each content control list entry
        For i = 1 To .DropdownListEntries.Count
            'Establish which selection is made
            If .DropdownListEntries(i).Text = .Range.Text Then
                'Put the value associated with that selection in the cell to the right of the one with the control
                .Range.Cells(1).Range.Next.Cells(1).Range.Text = .DropdownListEntries(i).Value
                'and stop processing
                Exit For
            End If
        Next
    End With
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