Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I add a horizontal scrollbar to a VBA ListBox

Tags:

vba

I'd like to add a horizontal scrollbar to a VBA ListBox.

It appears that the built in ListBox does not add a horizontal scrollbar automatically. I have a number of fields whose contents exceed the width of the ListBox and are thus unreadable to the user.

I found this article, however the code fails, due to accessing hwnd of the ListBox (which is apparently not available in VBA). I'd rather not write a native DLL to accomplish this as I suspect there is a better way.

Any idea on how I can add a horizontal scrollbar to a VBA ListBox?

I'm open to the idea of using an alternate control rather than getting it to work with the ListBox specifically.

like image 898
Tom Hennen Avatar asked Jan 24 '23 15:01

Tom Hennen


2 Answers

Did you try ColumnWidths property? I have listbox with horizontal scroll bar. I just had to add ColumnWidths property.

For example I have

me.Listbox1.Columnwidts ="0.5 in;0.2 in;1.5 in;0.75 in;0.5 in"

like image 104
THEn Avatar answered Jan 29 '23 23:01

THEn


Unless I'm missing something, a VBA listbox will automatically gain a horizontal scrollbar if the total of its ColumnWidths property exceeds its own width.

There are no properties I know of that affect this behaviour, i.e. I don't otherwise know how to force or disable display of the horizontal scrollbar.

like image 39
Lunatik Avatar answered Jan 30 '23 01:01

Lunatik