excel调用用户窗体_防止Excel用户窗体中的无效条目

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。

userformcombomatch02

添加选择项 (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".

因为空字符串不是有效的条目,所以会出现错误消息-“无效的属性值”。

userformcombomatch03

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.

为了防止出现该错误,您可以在下拉列表中添加“选择”作为第一项,然后将组合框重置为该项,而不是清除它们。

userformcombomatch01

下载示例组合框工作簿 (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调用用户窗体

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值