Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 02-22-2022, 03:11 PM
MarilynL MarilynL is offline Listbox, Multi-Select Windows 10 Listbox, Multi-Select Office 2021
Novice
Listbox, Multi-Select
 
Join Date: Feb 2022
Posts: 2
MarilynL is on a distinguished road
Angry Listbox, Multi-Select

I want to add a list box to my document allowing users to select multiple events from a list. I used the Developer tab to add a listbox, but it appears as an empty box, and I do not know how to populate it. I did select Properties and changed the Multi-Select field to MultiSelectExtended.



How do I populate my listbox?

Thank you.

P.S. I am using Word 365.
Reply With Quote
  #2  
Old 02-22-2022, 04:18 PM
Guessed's Avatar
Guessed Guessed is offline Listbox, Multi-Select Windows 10 Listbox, Multi-Select Office 2016
Expert
 
Join Date: Mar 2010
Location: Canberra/Melbourne Australia
Posts: 3,978
Guessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant future
Default

In a Word document I don't know of a listbox that can display the full list and allow multiselect. I have uses multiselect listboxs in vba userforms though.

The best I can suggest for a Word questionnaire is to use either
1. a dropdown list content control inside a repeating section content control
2. a series of check box content controls

If the document is intended to be used in soft or hard copy form then option 2 is the way I would do it.
__________________
Andrew Lockton
Chrysalis Design, Melbourne Australia
Reply With Quote
  #3  
Old 02-22-2022, 10:36 PM
gmayor's Avatar
gmayor gmayor is offline Listbox, Multi-Select Windows 10 Listbox, Multi-Select Office 2019
Expert
 
Join Date: Aug 2014
Posts: 4,106
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

One possibility is to use a rich text content control and use its OnEnter event to call a userform - see attached example.
Attached Files
File Type: dotm Example.dotm (34.6 KB, 63 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
  #4  
Old 02-23-2022, 02:16 PM
MarilynL MarilynL is offline Listbox, Multi-Select Windows 10 Listbox, Multi-Select Office 2021
Novice
Listbox, Multi-Select
 
Join Date: Feb 2022
Posts: 2
MarilynL is on a distinguished road
Default

@gmayor
I opened Example.dotm and that is the kind of multi-select list I would like to create, but I am not sure of exactly what steps to take. From the Developer tab, I can insert a rich text content control but am not sure what to do next. I opened Visual Basic and saw the code you used. Should I click Visual Basic > Insert > Userform next? How do I pull up and populate the OnEnter Event?

Thanks for further clarification.
Reply With Quote
  #5  
Old 02-23-2022, 09:57 PM
gmayor's Avatar
gmayor gmayor is offline Listbox, Multi-Select Windows 10 Listbox, Multi-Select Office 2019
Expert
 
Join Date: Aug 2014
Posts: 4,106
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

Open your template and the attachment. From the VBA editor drag the userform from the example to your template. Copy the code from the ThisDocument module to the ThisDocument module of your template. Add a rich text content control to your template and title it "Link 1". (You can title it whatever you like, but make the change in the code to match.)
The ThisDocument module contains the code you need to change to supply your list
Code:
Option Explicit

Private Sub Document_ContentControlOnEnter(ByVal ContentControl As ContentControl)
Dim oFrm As UserForm1 'The name of the userform
Dim i As Integer
Dim orng As Range
Dim sText As String
    If ContentControl.Title = "List 1" Then 'the name of the listbox
        Set oFrm = New UserForm1
        With oFrm
            With .ListBox1 'the name of the listbox
                'the items you want to add
                .AddItem "pizza"
                .AddItem "hamburgers"
                .AddItem "hot dogs"
                .AddItem "garden salad"
                .AddItem "potato salad"
                .AddItem "potato chips"
                .MultiSelect = fmMultiSelectMulti
            End With
            .Show
            With .ListBox1 'the name of the listbox
                For i = 0 To .ListCount - 1
                    If .Selected(i) = True Then
                        sText = sText & .List(i) & vbCr
                    End If
                Next i
                If Not sText = "" Then sText = Left(sText, Len(sText) - 1)
            End With
            Set orng = ContentControl.Range
            orng.Text = sText
            orng.End = orng.End + 1
            orng.Collapse 0
            orng.Select
        End With
    End If
    Unload oFrm
    Set oFrm = Nothing
End Sub
The userform code is
Code:
Option Explicit

Private Sub CommandButton1_Click()
    Hide
End Sub

Private Sub UserForm_QueryClose(Cancel As Integer, CloseMode As Integer)
    If CloseMode = vbFormControlMenu Then Cancel = True
lbl_Exit:
    Exit Sub
End Sub
__________________
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
Reply

Tags
list box, multi-select



Similar Threads
Thread Thread Starter Forum Replies Last Post
Listbox, Multi-Select Listbox to select field name from data JamesWood Word VBA 5 05-25-2021 02:42 PM
Multi-Select CC Dropdown Lists gmaxey Word VBA 1 01-10-2020 11:53 PM
Listbox, Multi-Select Yet another Multi-Select Listbox in Userform question Javir Word VBA 4 09-24-2019 01:01 AM
How to use an ActiveX Control to insert a multi select listbox in Word marksm33 Word 2 01-29-2014 05:21 PM
Listbox, Multi-Select Multi-select listbox help gvibe@hotmail.com Word VBA 1 07-19-2013 10:54 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 08:26 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