RE: listbox - questions by bryan
bryan
Thu Jul 24 10:30:02 PDT 2008
Works like a charm.
I had modify a bit as I am using the selected items to go out and insert a
file into the document. I don't wan't the selections on the form per se.
Thanks much for the help and the quick response,
Bryan
"Jean-Guy Marcil" wrote:
> "bryan" wrote:
>
> > I curently have been using combo boxes in userforms for users to select one
> > item from a list. What I also want to do is supply a list of endorsement
> > forms and allow them the ability to select multiple forms to be included with
> > the form.
> >
> > Can I use this same code and use listbox
> > or do I need to have a combo box loaded with the selections and an OK button
> > to load them to a listbox?
> > And then another OK button when complete?
> > If this then how do I get the values of the listbox?
>
> Here is some code that takes the selected values (if any) from a listbox and
> types them "as is" at the current selection in the currently active document.
> Note that when building the userfrom, you must set the listbox "multiSelect"
> property to "frmMultiSelectMulti", or do it in the initialize event.
>
> Main code:
>
> Option Explicit
>
> Sub Test()
>
> Dim UF As UserForm1
> Dim varRec As Variant
> Dim strRec As String
> Dim i As Long
> Dim boolSelected As Boolean
>
> Set UF = New UserForm1
> boolSelected = False
>
> With UF
> .Show
> For i = 0 To .ListBox1.ListCount - 1
> If .ListBox1.Selected(i) Then
> If Not boolSelected Then
> strRec = .ListBox1.List(i)
> boolSelected = True
> Else
> strRec = strRec & "|" & .ListBox1.List(i)
> End If
> End If
> Next
> If boolSelected Then
> varRec = Split(strRec, "|")
> End If
> End With
>
> Set UF = Nothing
>
> If Not boolSelected Then
> Selection.TypeText "Nothing was selected."
> Else
> For i = LBound(varRec) To UBound(varRec)
> Selection.TypeText varRec(i) & vbCrLf
> Next
> End If
>
> End Sub
>
>
> Userform code:
>
> Option Explicit
>
> Sub UserForm_Initialize()
>
> With Me.ListBox1
> .AddItem ("40%")
> .AddItem ("60%")
> .AddItem ("80%")
> .AddItem ("100%")
> .ListIndex = 0
> End With
>
> End Sub
>
> Sub CommandButton1_Click()
>
> Me.Hide
>
> End Sub
>
>