vba Excel ActiveX ListBox 每次更新都会缩小

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/28152501/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-12 05:58:02  来源:igfitidea点击:

Excel ActiveX ListBox Shrinks with each update

excelvbaexcel-vbalistbox

提问by mchac

I have a set of linked subs which work like this:

我有一组链接的子程序,它们的工作方式如下:

  1. A user types into an ActiveX TextBox
  2. A Change Event in that TextBox calls a sub in a Module
  3. That Module sub drives updating a named range in a sheet
  4. The range value drives updating a table of Excel cells that uses lookup functions based on the range value
  5. The table values are copied and pasted to a another range (to eliminate links to formulas)
  6. That pasted range is put into a ListBox using this (props to Rory for his patience):

    ActiveSheet.ListBox1.List = Sheets("Search Criteria Control").Range("G1:G21").Value

  1. 用户在 ActiveX 文本框中键入内容
  2. 该文本框中的更改事件调用模块中的子项
  3. 该模块子驱动更新工作表中的命名范围
  4. 范围值驱动更新使用基于范围值的查找函数的 Excel 单元格表
  5. 表值被复制并粘贴到另一个范围(以消除与公式的链接)
  6. 使用这个将粘贴的范围放入一个列表框(支持 Rory 的耐心):

    ActiveSheet.ListBox1.List = Sheets("Search Criteria Control").Range("G1:G21").Value

The result is that for every character the user types in the TextBox the ListBox is updated.

结果是,对于用户在 TextBox 中键入的每个字符,ListBox 都会更新。

The problem I have is that the ListBox shrinks a bit with every keystroke in the TextBox referred to in #1 above. Is this normal behavior and I'm misusing ListBoxes, am I doing something wrong or do I need to respecify the dimensions of the ListBox every time it is updated with something like this?

我遇到的问题是 ListBox 会随着上面 #1 中提到的 TextBox 中的每次击键而缩小一点。这是正常行为吗,我是否在滥用 ListBoxes,是我做错了什么,还是每次更新 ListBox 时都需要重新指定它的尺寸?

ActiveSheet.OLEObjects("ListBox1").Top = 35
ActiveSheet.OLEObjects("ListBox1").Left = 650
ActiveSheet.OLEObjects("ListBox1").Width = 550
ActiveSheet.OLEObjects("ListBox1").Height = 610

Thanks in advance for any thoughts on this.

预先感谢您对此的任何想法。

回答by CWiz

I was having trouble with the same thing. My ActiveX listbox would move around on the sheet and change size for no reason that I could see.

我遇到了同样的问题。我的 ActiveX 列表框会无缘无故地在工作表上移动并更改大小。

While I did go ahead and develop some code to reset size and coordinates, that wasn't satisfactory since there had to be a mechanism to trigger that code - something I didn't want to burden end-users with.

虽然我确实继续开发了一些代码来重置大小和坐标,但这并不令人满意,因为必须有一种机制来触发该代码——我不想给最终用户带来负担。

I found a better answer in another user forum. There's a Listbox Property called IntegralHeightwhose default property is True- something to do with screen resolution and optimal display of listbox contents. Simply set that to False. I did that with some ActiveX boxes that were giving me fits, and I was able to disable the "adjustment" code and, so far, so good!

我在另一个用户论坛中找到了更好的答案。有一个名为 Listbox 的属性,IntegralHeight其默认属性是True- 与屏幕分辨率和列表框内容的最佳显示有关。只需将其设置为False. 我用一些适合我的 ActiveX 盒子做到了这一点,我能够禁用“调整”代码,到目前为止,一切都很好!