![]() |
#2
|
||||
|
||||
![]()
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 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 You may find the list editor in https://www.gmayor.com/insert_content_control_addin.htm useful.
__________________
Graham Mayor - MS MVP (Word) (2002-2019) Visit my web site for more programming tips and ready made processes www.gmayor.com |
Thread Tools | |
Display Modes | |
|
![]() |
||||
Thread | Thread Starter | Forum | Replies | Last Post |
![]() |
Radders567 | Word VBA | 8 | 06-06-2020 12:41 AM |
Creating a drop down list that if (a) is selected then (x) happens | mummarochy | Word | 1 | 06-11-2018 10:07 PM |
Drop down box list based on response to another drop down box | Phideaux | Excel | 16 | 04-13-2018 03:07 AM |
Help creating a hyperlink drop down list between documents | SconnieGuy91 | Word | 3 | 11-30-2016 05:26 PM |
![]() |
celias | Word VBA | 3 | 07-11-2016 11:40 PM |