简体   繁体   English

Excel VBA多个复选框

[英]Excel VBA mulitiple checkboxes

is it possible to create listbox with multiple checkboxes in one row (Excel VBA)? 是否可以在一行中创建包含多个复选框的列表框(Excel VBA)?

Thanks Kamil 谢谢卡米尔

I'm not sure I understood your question fully, but I'll elaborate on ListBoxes as much as I can. 我不确定我完全理解你的问题,但我会尽可能详细地阐述ListBoxes。

  • First things first: Checkboxes and ListBoxes are different objects in Excel Userforms. 首先要做的事情: CheckboxesListBoxes是Excel Userforms中的不同对象。 The first is the little box that returns a "true/false". 第一个是返回“true / false”的小方框。 The second is a list of items which can be chosen. 第二个是可以选择的项目列表。 Clicking in a Checkbox will make the tick mark appear/disappear (or fade if tristate is enabled), while clicking a Listbox row will turn the listbox row "blue"/"white" (or whatever color is being used for the selected rows). 单击复选框将使勾号出现/消失(如果启用了三态,则为淡入淡出),而单击列表框行将使列表框行变为“蓝色”/“白色”(或所选行的任何颜色) 。 In both elements, clicking is a way to toggle between True and False. 在这两个元素中,单击是一种在True和False之间切换的方法。
  • While a checkbox only allows for a single information to be marked as True or False, a Listbox allows you to select entries out of a list. 虽然复选框仅允许将单个信息标记为True或False,但Listbox允许您从列表中选择条目。 That list may be inserted through code (.AddItem method) or passed from a range (.RowSource property) 该列表可以通过代码(.AddItem方法)插入或从范围(.RowSource属性)传递
  • ListBox objects allow for multiple columns of data to be attributed to one row element, but each row is an entire element (which means you cannot pick the element on row 3, column 2 - only all of row 3). ListBox对象允许将多列数据归属于一个行元素,但每行都是整个元素(这意味着您不能选择第3行第2列的元素 - 仅第3行的所有元素)。 The number of columns is established using the ColumnCount property. 使用ColumnCount属性建立列数。
  • By changing the value of the MultiSelect property, you'll allow the user to select multiple or single row elements simultaneously on your Listbox. 通过更改MultiSelect属性的值,您将允许用户在列表框上同时选择多个或单个行元素。 Using the Selected( RowIndex ) property, you can check whether or not an item is currently selected (returns True/False). 使用Selected( RowIndex 属性,可以检查当前是否选择了一个项目(返回True / False)。 Remember that row indexes start at 0. 请记住,行索引从0开始。
  • Finally, if you're using the MultiSelect property set to fmMultiSelectSingle and have a single column (as far as I know), the Text property can be used to return the selected item's value. 最后,如果您使用MultiSelect属性设置为fmMultiSelectSingle并且只有一列(据我所知), Text属性可用于返回所选项的值。

An easy example of a listbox is in Excel can be found at File > Options > Customize Ribbon (or something like that). 可以在文件>选项>自定义功能区 (或类似的东西)中找到Excel中列表框的简单示例。 There are two listboxes, one (on the left) with the visible items and another with the available items. 有两个列表框,一个(左侧)有可见项目,另一个有可用项目。 A pair of command buttons is used to move items between boxes. 一对命令按钮用于在框之间移动项目。 That's a simple application you can likely find already setup online. 这是一个简单的应用程序,您可能已经发现已经在线设置。

Am I on track to answer your question? 我有没有回答你的问题?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM