![]() |
|
|
|
#1
|
|||
|
|||
|
Hi guys
I'd like to create a form/listbox in Word that displays all the headings from a data source currently loaded for a mail merge, and then I can click and select one (which it will actually then use as a string, but irrelevant for this post). Please see the attached image. Any thoughts?? Would really help a ton. Thanks a lot! James |
|
#2
|
||||
|
||||
|
Do you mean like
Code:
Private Sub UserForm_Initialize()
Dim lngFld As Long
With ActiveDocument.MailMerge.DataSource
ListBox1.Clear
For lngFld = 1 To .FieldNames.Count
ListBox1.AddItem .FieldNames(lngFld)
Next
End With
End Sub
__________________
Graham Mayor - MS MVP (Word) (2002-2019) Visit my web site for more programming tips and ready made processes www.gmayor.com |
|
#3
|
|||
|
|||
|
Quote:
Amazing! Thanks so much!!! |
|
#4
|
|||
|
|||
|
Quote:
So I'm wondering how I can store one of the fields as a string. So basically on the listbox, I click on the desired field name, then when I click OK it stores that field name as a string. Any thoughts please? Thanks so much |
|
#5
|
|||
|
|||
|
Actually I managed to make a string from the selected listbox field
![]() ' Make a string from the selected listbox field For var = 0 To ListBox1.ListCount - 1 If ListBox1.Selected(var) = True Then docNameField = docNameField & ListBox1.List(var) _ & vbCrLf End If Next I'm not sure why I'm getting this error though: "The requested member of the collection does not exist" On this line of code: strDocName = ActiveDocument.MailMerge.DataSource.DataFields(doc NameField).Value & ".pdf" Thoughts? It's getting stuck at the docNameField part I think but I don't know why. |
|
#6
|
|||
|
|||
|
No worries I figured it out
Thanks
|
|
| Tags |
| listbox |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
Yet another Multi-Select Listbox in Userform question
|
Javir | Word VBA | 4 | 09-24-2019 01:01 AM |
| How to filter data before it is pulled into combobox/listbox AND remove data from listbox | Izzii0x | Excel Programming | 8 | 05-24-2019 07:25 AM |
| Add-In creates ListBox from XLS, but data not saved in ppt | barbet | PowerPoint | 0 | 05-26-2016 02:30 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 |