View Single Post
 
Old 07-05-2018, 04:27 AM
gmayor's Avatar
gmayor gmayor is offline Windows 10 Office 2016
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

You will need a couple of macros for this.


Looking at your illustration suggests that the list has a title "Quality 2015", and that all the entries begin with 9001. (If there are other sequences you will need to modify the macro to address them)

The following macro will split that list to show only the numbers while retaining the value as the full texts shown:
Code:
Sub Macro1()
Dim oCC As ContentControl
Dim i As Integer
Dim strValue As String, strText As String
Dim Coll As Collection
    Set oCC = ActiveDocument.SelectContentControlsByTitle("Quality 2015").Item(1)
    Set Coll = New Collection
    With oCC.DropdownListEntries
        For i = 1 To .Count
            strValue = .Item(i).Text
            strText = onlyDigits(.Item(i).Text)
            strText = Replace(strText, "9001", "9001 ")
            Coll.Add strText & "|" & strValue
        Next i
        .Clear
        .Add "Choose an item", ""
        For i = 1 To Coll.Count
            .Add Split(Coll.Item(i), "|")(0), Split(Coll.Item(i), "|")(1)
        Next i
    End With
End Sub

Private Function onlyDigits(s As String) As String
Dim retval As String
Dim i As Integer
    retval = ""
    For i = 1 To Len(s)
        If Mid(s, i, 1) >= "0" And Mid(s, i, 1) <= "9" _
           Or Mid(s, i, 1) = "." Then
            retval = retval + Mid(s, i, 1)
        End If
    Next
    onlyDigits = retval
End Function
Run the macro to modify the list.
Then add the following macro to the ThisDocument module of the document:
Code:
Option Explicit

Private Sub Document_ContentControlOnExit(ByVal CC As ContentControl, Cancel As Boolean)
Dim lngIndex As Long
Dim strValue As String
    Select Case CC.Title
        Case "Quality 2015"
            If CC.ShowingPlaceholderText Then GoTo lbl_Exit
            With CC
                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
Select a number, then click outside the control to display the value. See attached mock-up


You may find the list editor in https://www.gmayor.com/insert_content_control_addin.htm useful.
Attached Files
File Type: docm ShowList_InsertValue.docm (36.9 KB, 13 views)
__________________
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