

- #MS WORD COMBO BOX FUNCTION CODE#
- #MS WORD COMBO BOX FUNCTION SERIES#
- #MS WORD COMBO BOX FUNCTION DOWNLOAD#
'Set the number of columns in the Listbox to match the number of columns in the table of detailsĪrrData(m, n) = Main.fcnCellText(sourcedoc.Tables(1).Cell(m + 2, n + 1)) 'Get the number of columns in the table of details 'Get the number members = number of rows in the table of details less one for the header row Set sourcedoc = Documents.Open(FileName:="D:\Data Stores\sourceWordII.doc", Visible:=False) 'Open the file containing the table with items to load 'Define an array to be loaded with the data In this case you collect the data from the source as previously shown and then hide all but the primary data.įor this example, I used a source document saved as "D:\Data Stores\sourceWordII.doc"ĭim i As Long, j As Long, m As Long, n As Long 'Returns specifically column 0, ListIndex 0 (first item/first column)Įxample 2 - There may be times when you want multi-column data available, but you only want to display primary data and then use all or only parts of the available data.

'Returns data contained in the third column of the row selected.

Remember listbox columns are indexed starting with 0. ' Returns value in the second column of the selected row (.ListIndex) _ BoundColumn = 1 actually means listbox column 0. TextColumn properties settings are indexed starting at 1 _ 'Return value or content from bound column of selected row.

'Get the number of list member attritbutes (i.e., table columns) 'Get the number of list members (i.e., table rows - 1 if header row is used) Set sourcedoc = Documents.Open(FileName:="D:\Data Stores\sourceWord.doc", Visible:=False) 'Modify the following line to point to your list member file and open the document
#MS WORD COMBO BOX FUNCTION CODE#
#MS WORD COMBO BOX FUNCTION SERIES#
Word MVP Doug Robbins has posted this method regularly in the Microsoft Word Public newsgroups.Įxample 1 - The following series of illustrations show: The first method uses a Microsoft Word table contained in a separate document as the external source. Next we will look at some methods for using an external data source to populate a listbox. Note columns are indexed _Įach of the previous examples used data contained in the userform Initialize event to create the listbox list members. 'Write userform data to bookmarked ranges in the document. List method to write array data to specific listbox row and column. AddItem method to add a multi-column row for each array element. ColumnWidth property to set column widths. & "Arkansas|California|Connecticut|Etc.", "|")ĪrrStateAbbv = Split(" |AL|AK|AZ|AR|CA|CT|Etc", "|") 'Use the Split function to create two zero based one dimensional arrays.ĪrrStateName = Split("Select State|Alabama|Alaska|Arizona|" _ A combobox can be configured to accept pre-defined list entries only or allow the user to enter his or her own text.
#MS WORD COMBO BOX FUNCTION DOWNLOAD#
You can download the demonstration document containing all of the example userforms and VBA procedures used to prepare this tips page with the link at the end of the page.Ī listbox provides users with a convenient means of selecting one or more items from a fixed pre-defined list.Ī combobox provides users with a compact and convenient means of selecting a single item from a pre-defined list. For brevity, I will use one term or the other in the examples that follow.ģ. The basic process for populating a listbox or combobox is the same. See my Create & Employ a Userform tips page for information on creating and employing userforms.Ģ. Microsoft Word MVP Doug Robbins has kindly assisted with the preparation of this page. This Microsoft Word Tips & Microsoft Word Help page demonstrates several methods that you can use to populate a userform listbox (or combobox).
