![]() |
|
#5
|
||||
|
||||
|
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
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 |
| Tags |
| list box, multi-select |
| Thread Tools | |
| Display Modes | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
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 |
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 |
Multi-select listbox help
|
gvibe@hotmail.com | Word VBA | 1 | 07-19-2013 10:54 AM |