![]() |
|
#1
|
|||
|
|||
|
i have created a drop down list content control.
what i want to do is when i hit the drop down it will display an in depth wording however when i select the option it display on the document as a cut down named version. for instance in the attached image of my current content control list the displayed is the in depth wording, however once selected which one i want it then displays as for instance in relation to the top one 9001 4.1 Understanding the Organization and its context i want it to display as 9001 - 4.1 Is there a way of doing this ? |
|
#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 |
|
#3
|
|||
|
|||
|
yeah thats what i want to do but the other way around, for instance it has the larger amount of writing in the drop down but when you select an option it then outputs the smaller version.
Thanks in advance for your help. |
|
#4
|
||||
|
||||
|
You can use a ContentControlOnExit macro coded as:
Code:
Private Sub Document_ContentControlOnExit(ByVal CCtrl As ContentControl, Cancel As Boolean)
Dim t As Long
With CCtrl
If .Title <> "QMS 2015" Then Exit Sub
If .ShowingPlaceholderText = True Then Exit Sub
t = .Type
.Type = wdContentControlText
With .Range
.Text = Split(.Text, " ")(0) & " " & Split(.Text, " ")(1)
End With
.Type = t
End With
End Sub
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
|
#5
|
|||
|
|||
|
thanks for the reply, im unsure how to use this ?
|
|
#6
|
||||
|
||||
|
Simply add the macro to the 'ThisDocument' code module of your document or its template.
For PC macro installation & usage instructions, see: http://www.gmayor.com/installing_macro.htm
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
|
#7
|
|||
|
|||
|
ok thanks i will try this, i cant see within the code how it tells the content box to change the words, for instance one of the options is 9001 4.1 Understanding the Organization and its context and i want it to display 9001:2015 - 4.1 when i select it.
|
|
#8
|
||||
|
||||
|
Perhaps you should try it. Having seen what it does, you might then try to figure out the how.
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
|
#9
|
||||
|
||||
|
Quote:
Provided it is the same added text each time i.e. ':2015 - ' then the following macro will mofify your list to do that (at least as far as the list was shown in the original screen shot) 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 = 2 To .Count
strText = .Item(i).Text
strValue = onlyDigits(.Item(i).Text)
strValue = Replace(strValue, "9001", "9001:2015 - ")
Coll.Add Trim(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
__________________
Graham Mayor - MS MVP (Word) (2002-2019) Visit my web site for more programming tips and ready made processes www.gmayor.com |
|
#10
|
||||
|
||||
|
Quote:
Quote:
It seems we're working with a moving target here...
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
|
| Thread Tools | |
| Display Modes | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
Creating a reducing drop down list
|
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 |
Having a Drop-down list in Word referring to an Excel list
|
celias | Word VBA | 3 | 07-11-2016 11:40 PM |