Prev: Subscript problem
Next: Name Directory
From: Jeff on 25 Feb 2010 11:24 Greetings, I have a userform with a lisbox on it that allows multiple selections. I would like to add FormFields for each of the selected items and add the selected items text as the form field result property following a button click event. Is this possible and any Ideas how to accomplish this? TIA.
From: Fumei2 via OfficeKB.com on 25 Feb 2010 14:21 Yes, it is possible. May I ask why you are using a text formfield to hold the selected items text? Formfields are for user input, not to hold text. If the user is not going to be changing the text - therefore changing the text of the selected item - do not use a formfield. Second question. WHERE do you want to put the new formfields? One right the other, butting up to each other? Try recording a macro inserting a formfield, and look at the code. As for getting the selected items, something like: For j = 0 To ListBox1.ListCount If ListBox1.Selected(j) = True Then ReDim Preserve MyList(l) MyList(l) = ListBox1.List(j) l = l + 1 End If Next This builds an array of the selected items. Now you can use the array to insert new formfields. Use a formfield object. Something like: Dim NewFormField As FormField For k = 0 To Ubound(MyList()) ' insert a formfield.....where?? Set NewFormField = Selection.FormFields.Add(Range:=Selection.Range, _ Type:=wdFieldFormTextInput) With NewFormField .Result = MyList(k) ' the current selected item from the array .Name = "NewOne" & k End With Next Jeff wrote: >Greetings, >I have a userform with a lisbox on it that allows multiple selections. I >would like to add FormFields for each of the selected items and add the >selected items text as the form field result property following a button >click event. Is this possible and any Ideas how to accomplish this? TIA. -- Message posted via OfficeKB.com http://www.officekb.com/Uwe/Forums.aspx/word-programming/201002/1
From: Jeff on 26 Feb 2010 08:59 Fumei, Thanks for the reply. When I posted this question I was attempting to use a single Formfield to hold several lines of text. After some research and some trial and error I came up with: Sub AddToDocument(ByVal aString As String, ByVal I As Integer) Dim ff As FormField Set ff = ActiveDocument.FormFields.Add(Selection.Range, wdFieldFormTextInput) With ff .Name = "Document" & I .Result = aString & vbCr End With End Sub Allowing me to add a FormField for each line of text passed to the procedure. "Fumei2 via OfficeKB.com" wrote: > Yes, it is possible. May I ask why you are using a text formfield to hold > the selected items text? Formfields are for user input, not to hold text. > If the user is not going to be changing the text - therefore changing the > text of the selected item - do not use a formfield. > > Second question. WHERE do you want to put the new formfields? One right the > other, butting up to each other? > > Try recording a macro inserting a formfield, and look at the code. > > As for getting the selected items, something like: > > For j = 0 To ListBox1.ListCount > If ListBox1.Selected(j) = True Then > ReDim Preserve MyList(l) > MyList(l) = ListBox1.List(j) > l = l + 1 > End If > Next > > This builds an array of the selected items. Now you can use the array to > insert new formfields. Use a formfield object. Something like: > > Dim NewFormField As FormField > > For k = 0 To Ubound(MyList()) > ' insert a formfield.....where?? > Set NewFormField = Selection.FormFields.Add(Range:=Selection.Range, _ > Type:=wdFieldFormTextInput) > With NewFormField > .Result = MyList(k) ' the current selected item from the array > .Name = "NewOne" & k > End With > Next > > > > Jeff wrote: > >Greetings, > >I have a userform with a lisbox on it that allows multiple selections. I > >would like to add FormFields for each of the selected items and add the > >selected items text as the form field result property following a button > >click event. Is this possible and any Ideas how to accomplish this? TIA. > > -- > Message posted via OfficeKB.com > http://www.officekb.com/Uwe/Forums.aspx/word-programming/201002/1 > > . >
|
Pages: 1 Prev: Subscript problem Next: Name Directory |