![]() |
|
#1
|
|||
|
|||
![]()
Hi all,
I'm looking for code which will allow users to select an option from a dropdown list which then puts the selection below the dropdown. When the next option is selected, it puts that selection beneath the previous one, and so on e.g. [dropdown with options 1,2,3,4] (selection results in...) 4 2 1 3 (...or whatever order they were selected). Hoping someone can point me in the right direction. Thanks! |
#2
|
|||
|
|||
![]()
What kind of dropdown list?
|
#3
|
|||
|
|||
![]()
Hi Greg,
I was thinking just a content control dropdown. If there's a better way of doing it, I'm open to that too. I've attached a doc with the type of dropdown and an example of the type of output expected. Thanks. |
#4
|
|||
|
|||
![]()
If you title your CC "DDLists" and put this in the ThisDocument Module of the VB Project, it will do what your describe when the user exits the CC.
Code:
Option Explicit Private Sub Document_ContentControlOnExit(ByVal ContentControl As ContentControl, Cancel As Boolean) Dim oRng As Range Select Case ContentControl.Title Case "DDList" Set oRng = ContentControl.Range.Paragraphs(1).Range oRng.Collapse wdCollapseEnd oRng.InsertAfter ContentControl.Range.Text & vbCr End Select lbl_Exit: Exit Sub End Sub |
#5
|
|||
|
|||
![]()
Oops, I read your requirement wrong. To append the next value selected to the end of the list you will need a second RichText CC titled "List"
Code:
Option Explicit Private Sub Document_ContentControlOnExit(ByVal ContentControl As ContentControl, Cancel As Boolean) Dim oRng As Range Select Case ContentControl.Title Case "DDList" Set oRng = ActiveDocument.SelectContentControlsByTitle("List").Item(1).Range oRng.Collapse wdCollapseEnd oRng.InsertAfter vbCr & ContentControl.Range.Text End Select lbl_Exit: Exit Sub End Sub You may find this helpful: (Pseudo Multi-Select Dropdown Content Controls |
#6
|
||||
|
||||
![]()
It would be possible to produce this with a macro on the Content Control but the useability would be awful requiring lots of mouse clicks. I would recommend vba userform with a Listbox like the attached doc. Double click the first line to start the macro which opens the userform then click away.
__________________
Andrew Lockton Chrysalis Design, Melbourne Australia |
#7
|
|||
|
|||
![]()
Andrew,
I agree. The requested process and my proposed "basic" solution is not ideal. That is why I posted the link. Your example works well. Thanks. |
#8
|
|||
|
|||
![]()
@Greg, thanks for your input.
@Andrew, thanks for the file sample. If I want to edit the options for selection, so the available options are "duck", "cat", "goat" etc. or longer strings, any idea how I would do that? Thanks again, Emlyn. |
#9
|
||||
|
||||
![]()
If you are going to change the options then you should be specific about what it is you 'really' want. How long are those longer strings going to get?
If you view the VBA code in the Userform, you can edit the following macro to remove the green lines below and replace them with the three lines shown in red below. Code:
Private Sub UserForm_Initialize() ' Dim i As Integer ' With Me.lbox ' For i = 1 To 10 ' .AddItem "Option " & i ' Next i ' End With Dim sArr() As String sArr = Split("cat|dog|donkey|camel|draught horse and its cart", "|") Me.lbox.List = sArr End Sub
__________________
Andrew Lockton Chrysalis Design, Melbourne Australia |
#10
|
|||
|
|||
![]()
Andrew,
That's brilliant. Thanks again for this. Have a good one! |
![]() |
|
![]() |
||||
Thread | Thread Starter | Forum | Replies | Last Post |
![]() |
lgsikaffy | Word VBA | 3 | 12-14-2018 05:14 PM |
![]() |
snowboarder2 | Excel | 7 | 08-30-2018 09:20 AM |
Selection of a dropdown creates another dropdown wih the list | krishnamurthy.ka2810 | Word VBA | 1 | 04-26-2018 11:44 PM |
![]() |
lopesdasilva | Word | 2 | 05-31-2016 01:30 AM |
![]() |
trainsy | Word | 2 | 06-04-2014 04:43 AM |