删除 Excel VBA 用户窗体中列表框的滚动条

Removing the scroll bar on a list box in Excel VBA UserForms

我在 Excel VBA 中使用用户窗体,并且我有一个样式为 fmStyleDropDownList 的组合框。我想删除水平滚动条:

请记住,此问题与此问题有些相似: Remove the scroll bar on a list box。在此 post 中,公认的解决方案指出:

This can occur when you have the column width format property of the listbox set to something wide, then you size the control to the data, it will show the scroll bars.

To fix this, change the "Column Width" property under the format tab to something really small, then play around with this property and the size of the listbox control until you get it how you want, and no scroll bars are displayed.

所以我所做的是:我将 ColumnWidths 属性 更改为更小的值,直到水平滚动条消失。但是,这样做的副作用是下拉文本没有足够的宽度作为一个整体显示,如下图所示(Width 和 LastWidth 属性 保持在 162):

  • Picture of my combo box with ColumnWidths of 50 pt。滚动条还在。而不是“abcdefghijklmn”,只有“abcdefghijkl”(没有mn)显示在下拉菜单的第二行,第三行显示“something e”而不是“something else”。我认为这是因为 ColumnWidths 属性 设置得太小了。
  • Picture of my Combo box with ColumnWidths of 18 pt。滚动条不见了(这就是我想要的)。 18 pt 是我在没有滚动条的情况下得出的最大值。但是它现在在下拉菜单的任何一行中只显示几个(18?)点,这对我来说是无法接受的。

有什么解决办法吗?

正如 Siddharth Rout 指出的那样,问题是由多列引起的。将 ColumnCount 属性 设置回 1 可解决此问题。