excel调用用户窗体
In an Excel UserForm, you can use combo boxes, to show users a drop down list of items. If all goes well, the users will select an item from the list, and life will be good.
在Excel UserForm中 ,可以使用组合框向用户显示项目的下拉列表。 如果一切顺利,用户将从列表中选择一个项目,生活将会美好。
However, the occasional user likes to get creative, and types an entry that isn't in the drop down list. And that can cause problems!
但是,偶尔的用户喜欢创意,并输入下拉列表中没有的条目。 这可能会导致问题!
To restrict those creative users, you can set the MatchRequired property for the combo box to True.
要限制这些创意用户,可以将组合框的MatchRequired属性设置为True。
添加选择项 (Add a Select Item)
Changing that MatchRequired property can cause problems though. In this example, the Excel VBA code also tries to clear out the combo boxes, after adding an order to the parts database sheet.
但是,更改该MatchRequired属性可能会导致问题。 在此示例中,在向零件数据库工作表添加订单之后,Excel VBA代码还尝试清除组合框。
Because an empty string isn't a valid entry, an error message appears -- "Invalid Property Value".
因为空字符串不是有效的条目,所以会出现错误消息-“无效的属性值”。
To prevent that error from appearing, you can add "Select" as the first item in the drop down list, and reset the combo boxes to that item, instead of clearing them out.
为了防止出现该错误,您可以在下拉列表中添加“选择”作为第一项,然后将组合框重置为该项,而不是清除它们。
下载示例组合框工作簿 (Download the Sample Combo Box Workbook)
To download the sample file, go to the Excel Templates page on my Contextures site. In the UserForms section, look for UF0026 - Prevent Invalid Entries in UserForm.
要下载示例文件,请转到我的Contextures网站上的“ Excel模板”页面。 在“用户窗体”部分中,查找UF0026-防止UserForm中的无效条目 。
The file is in Excel 2003 format, and zipped. Enable macros after opening the workbook.
该文件为Excel 2003格式,并已压缩。 打开工作簿后启用宏。
观看Excel UserForm组合框匹配视频 (Watch the Excel UserForm Combo Box Match Video)
To see the steps for changing the MatchRequired setting, and editing the code, you can watch this short Excel video tutorial.
要查看更改MatchRequired设置和编辑代码的步骤,您可以观看这段简短的Excel视频教程。
翻译自: https://contexturesblog.com/archives/2011/06/13/prevent-invalid-entries-in-excel-userform/
excel调用用户窗体