禁用用户窗体上的按钮 [英] Disable button on a userForm

查看:27
本文介绍了禁用用户窗体上的按钮的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我的电子表格中的某个单元格等于某个数字,我正在尝试弄清楚如何禁用我的用户窗体中的按钮.我尝试了下面所述的代码,但它不起作用.

I'm trying to figure out how to disable a button within my userForm if a certain cell within my spreadsheet equals a certain number. I tried the code stated below, but it isn't working.

Private Sub UserForm_Initialize()
Label2 = Sheets("DATA").Range("AM2").Value
Label4 = Sheets("DATA").Range("AO2").Value
Label7 = Format(Sheets("DATA").Range("R8").Value, "Currency")

If Sheets("DATA").Range("AL10").Value = 10 Then
ActiveSheet.Shapes("CommandButton1").Select
UserFormact_Upgrade.CommandButton1.Enabled = False

Else


End If

End Sub

推荐答案

您的代码应该可以正常工作,因为您走在正确的道路上.

Your code should be working, as you're on the right path.

要测试它,只需创建一个新表单并添加此代码,您就会看到它应该可以工作.也许您在 IF 子句中遇到了问题?

To test it, simply create a new form and add this code, you'll see it should work. Maybe you're having problems within the IF clause?

此外,您不需要在禁用它之前选择形状;立即禁用它.

Besides, you don't need to select the shape prior to disabling it; just disable it right away.

Private Sub UserForm_Initialize()

    CommandButton1.Enabled = False

End Sub

这篇关于禁用用户窗体上的按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆