Vba – Add header row to listbox

ms-wordvba

I am using listboxes to display data in userforms in word. However I am not able to set header captions or figure out how to make it possible to click on the header to sort by that column.

GUI.Search_ListBox.Clear
GUI.Search_ListBox.ColumnCount = 5 ' Columns
GUI.Search_ListBox.ColumnWidths = "120;80;70;120;300"
GUI.Search_ListBox.ColumnHeads = True
'GUI.Search_ListBox.RowSource = "Hello;gkjfl;hsjgh;hdfjhgkj;fdjghjkdf" 'here it fails!!!

enter image description here

Best Answer


With VBA, simply set the ListBox.ColumnHeads Property to True.


Alternatively, you can also change the setting in the ActiveX control's Properties dialog:

Properties

If the Properties button is disabled on the ribbon, you'll have to enter Design Mode first.


More Information:


EDIT:

You need to specify the headings in the rowsource:

Column headings are enabled and either field captions, field names, or the first row of data items are used as column headings.

Related Topic