【问题标题】:Reset command for TextBoxes and Comboboxes文本框和组合框的重置命令
【发布时间】:2019-04-08 17:25:13
【问题描述】:

我有一个带有重置命令按钮的 excel 用户表单,用于清除用户字段。 我的用户表单由文本框和组合框组成。我使用下面的脚本来重置字段。问题是它没有清除组合框中的值,因为我使用了icontrol.name like "Txt*"。我试过"Txt*","Comb*",但它给了我一个错误

Private Sub CmdReset_Click()

Dim iControl As Control

For Each iControl In Me.Controls
If iControl.Name Like "Txt*" Then iControl = vbNullString
Next

End Sub

【问题讨论】:

  • 它给你什么错误?
  • 添加 " 或 iControl.Name 像 "Comb*"。
  • 非常感谢@Guest

标签: excel vba


【解决方案1】:

为了更准确,您可以使用以下方法:

For Each iControl In Me.Controls
   If TypeName(iControl) = "TextBox" Or TypeName(iControl) = "ComboBox" then iControl.Value = vbNullString
Next iControl

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-10-11
    • 2012-02-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-07
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多