Excel VBA,如果一个或多个文本框为空,如何禁用commandbutton

Excel VBA,如果一个或多个文本框为空,如何禁用commandbutton,excel,vba,Excel,Vba,我需要一个帮助,我制作了一个带有1个CommandButton和4个TextBox的userform,我想做的是。如果4个文本框仍然为空,我想禁用CommanButton 我已经找到了一个代码,帮助只有一个文本框,我使用的代码 专用子文本框1_Change() 如果TextBox1.Value=”“,则 CommandButton1.Enabled=False 否则 CommandButton1.Enabled=True 如果结束 端接头 当我在textbox2中使用相同的代码时,我结束卡住,当

我需要一个帮助,我制作了一个带有1个CommandButton和4个TextBox的userform,我想做的是。如果4个文本框仍然为空,我想禁用CommanButton

我已经找到了一个代码,帮助只有一个文本框,我使用的代码

专用子文本框1_Change()

如果TextBox1.Value=”“,则

CommandButton1.Enabled=False

否则

CommandButton1.Enabled=True

如果结束

端接头

当我在textbox2中使用相同的代码时,我结束卡住,当我使用代码时,commandbutton为enable(如果TextBox1.value&textbox2.value&TextBox3.value&TextBox4.value=“”,则commandbutton1.enabled=false) 填充文本框1后,命令按钮仍然处于启用状态

有什么想法吗?

使用:

If TextBox1.Value & TextBox2.Value & TextBox3.Value & TextBox4.Value = "" Then
如果值的串联为空,则所有值都必须为空。

使用:

If TextBox1.Value & TextBox2.Value & TextBox3.Value & TextBox4.Value = "" Then

如果值的串联为空,则所有值都必须为空。

不需要任何If条件

CommandButton1.Enabled = cbool(Len(Textbox1.Text) + Len(Textbox2.Text) _
                          + Len(Textbox3.Text) + Len(Textbox4.Text))

CBool(x)=True,而x是除0以外的任何数字,在这种情况下,结果为False。如果任何文本框包含任何内容,它们的组合长度将大于0,因此CBool的结果为True。

您不需要任何If条件

CommandButton1.Enabled = cbool(Len(Textbox1.Text) + Len(Textbox2.Text) _
                          + Len(Textbox3.Text) + Len(Textbox4.Text))

CBool(x)=True,而x是除0以外的任何数字,在这种情况下,结果为False。如果任何文本框包含任何内容,则它们的组合长度将大于0,因此CBool的结果,正确。

如果所有框都是空的,你想禁用吗?如果所有框都是空的,我想禁用..如果所有框都是空的,你想禁用吗?如果所有框都是空的,我想禁用..聪明的方法!聪明的方法!