Microsoft Office Forums

Go Back   Microsoft Office Forums > >

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
  #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,144
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 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
 

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 10:12 AM.


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