以下是引用57wk在2007-9-4 21:20:07的发言:请教菊花版主,学了5楼讲的按钮隐藏后还没得要领。我希望当某一单元格(如B5)为空时,按钮1就隐藏;反之,当(如B5)不为空时,按钮1就显示。这代码应怎样写?我下面这段代码错在何处? Private Sub Calendar1_Click() If Sheet1.[b5] = "" Then CommandButton1.Visible = False If Sheet1.[b5] <> "" Then CommandButton1.Visible = True End If End If End Sub 当单元格的值发生变化时,影响到按钮Visible属性的变化。这种情况下,应该把代码写在工作表的Worksheet_Change事件中: Private Sub Worksheet_Change(ByVal Target As Range) If Target.Address = "$B$5" Then If Target = "" Then CommandButton1.Visible = False Else CommandButton1.Visible = True End If End If End Sub 代码可以这样写: Private Sub Worksheet_Change(ByVal Target As Range) If Target.Address = "$B$5" Then CommandButton1.Visible = Target <> "" End If End Sub 或者: Private Sub Worksheet_Change(ByVal Target As Range) If Target.Address = "$B$5" Then CommandButton1.Visible = Target <> "" End Sub
rjFqJReQ.zip
(6.84 KB, 下载次数: 77)
|