Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 07-05-2018, 02:15 AM
killoffski killoffski is offline creating drop down list Windows 10 creating drop down list Office 2016
Novice
creating drop down list
 
Join Date: Jul 2018
Posts: 4
killoffski is on a distinguished road
Default creating drop down list

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 ?
Attached Images
File Type: jpg Untitled.jpg (113.7 KB, 26 views)
Reply With Quote
  #2  
Old 07-05-2018, 04:27 AM
gmayor's Avatar
gmayor gmayor is offline creating drop down list Windows 10 creating drop down list Office 2016
Expert
 
Join Date: Aug 2014
Posts: 4,101
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 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, 11 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
  #3  
Old 07-05-2018, 10:18 AM
killoffski killoffski is offline creating drop down list Windows 10 creating drop down list Office 2016
Novice
creating drop down list
 
Join Date: Jul 2018
Posts: 4
killoffski is on a distinguished road
Default

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.
Reply With Quote
  #4  
Old 07-05-2018, 04:28 PM
macropod's Avatar
macropod macropod is offline creating drop down list Windows 7 64bit creating drop down list Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,962
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

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]
Reply With Quote
  #5  
Old 07-05-2018, 04:40 PM
killoffski killoffski is offline creating drop down list Windows 10 creating drop down list Office 2016
Novice
creating drop down list
 
Join Date: Jul 2018
Posts: 4
killoffski is on a distinguished road
Default

thanks for the reply, im unsure how to use this ?
Reply With Quote
  #6  
Old 07-05-2018, 04:46 PM
macropod's Avatar
macropod macropod is offline creating drop down list Windows 7 64bit creating drop down list Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,962
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

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]
Reply With Quote
  #7  
Old 07-05-2018, 05:31 PM
killoffski killoffski is offline creating drop down list Windows 10 creating drop down list Office 2016
Novice
creating drop down list
 
Join Date: Jul 2018
Posts: 4
killoffski is on a distinguished road
Default

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.
Reply With Quote
  #8  
Old 07-05-2018, 07:36 PM
macropod's Avatar
macropod macropod is offline creating drop down list Windows 7 64bit creating drop down list Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,962
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

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]
Reply With Quote
  #9  
Old 07-05-2018, 08:36 PM
gmayor's Avatar
gmayor gmayor is offline creating drop down list Windows 10 creating drop down list Office 2016
Expert
 
Join Date: Aug 2014
Posts: 4,101
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 of
Default

Quote:
Originally Posted by killoffski View Post
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.
Neither of the options will do this as you have added text to the string.

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
Attached Files
File Type: docm ShowList_InsertValue.docm (39.4 KB, 12 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
  #10  
Old 07-05-2018, 08:45 PM
macropod's Avatar
macropod macropod is offline creating drop down list Windows 7 64bit creating drop down list Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,962
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

Quote:
Originally Posted by gmayor View Post
Neither of the options will do this as you have added text to the string.
Indeed, whereas the OP originally said:
Quote:
Originally Posted by killoffski View Post
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
which is what the code I posted does (except for the '-' insertion) now he's saying:
Quote:
Originally Posted by killoffski View Post
i want it to display 9001:2015 - 4.1 when i select it.
It seems we're working with a moving target here...
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
Reply



Similar Threads
Thread Thread Starter Forum Replies Last Post
creating drop down list 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
creating drop down list Having a Drop-down list in Word referring to an Excel list celias Word VBA 3 07-11-2016 11:40 PM

Other Forums: Access Forums

All times are GMT -7. The time now is 09:00 PM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2024 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft