我在用户表单上有两个选项按钮。如果您选择一个,它会灰色并禁用某些输入框ind如果您选择另一个,它会限制其他输入框并且效果很好。所以我有适当的代码来执行我想要的。但是,如果用户出错并单击一个选项然后尝试更改其选择,则代码已执行并禁用这些输入。如何让代码来回切换?这是我的代码,非常感谢您的帮助!
Sub Yes_Click()
If Yes.Value = True Then
With Me.IncrementalImpactPricingInput1
.Enabled = False
.BackColor = RGB(128, 128, 128)
End With
With Me.IncrementalImpactFundingInput1
.Enabled = False
.BackColor = RGB(128, 128, 128)
Me.BilledAmountInput1.Enabled = True
End With
Else: Call No_Click
End If
End Sub
Sub No_Click()
If No.Value = True Then
With Me.BilledAmountInput1
.Enabled = False
.BackColor = RGB(128, 128, 128)
End With
Else: Call Yes_Click
'With Me.IncrementalImpactPricingInput1
'.Enabled = True
'.BackColor = RGB(255, 255, 255)
'End With
'With Me.IncrementalImpactFundingInput1
'.Enabled = True
'.BackColor = RGB(255, 255, 255)
'End With
End If
End Sub
答案 0 :(得分:0)
您正在使用两个选项按钮,就好像它们是两个“圆形”复选框一样,强制您添加代码以使它们彼此保持同步。 相反,它们应该包含在一个选项组中,该组自动处理切换。在选项组中,分配选项按钮数据值1和2.然后将以下事件处理程序替换为:
Sub frameYesNo_AfterUpdate()
Select Case frameYesNo
Case 1: ' "yes" stuff here
Case 2: ' "no" stuff here
End Select
End Sub
答案 1 :(得分:0)
试试这个:(不知道这是不是你想要的)
'单击以锁定
Private Sub No_Click()
With Me.BilledAmountInput1
.Enabled = False
.BackColor = RGB(128, 128, 128)
End With
End Sub
'双击解锁
Private Sub No_DblClick(ByVal Cancel As MSForms.ReturnBoolean)
With Me.BilledAmountInput1
.Enabled = True
.BackColor = RGB(255, 255, 255)
End With
No.Value = False
End Sub
'单击以锁定
Private Sub Yes_Click()
With Me.IncrementalImpactPricingInput1
.Enabled = False
.BackColor = RGB(128, 128, 128)
End With
With Me.IncrementalImpactFundingInput1
.Enabled = False
.BackColor = RGB(128, 128, 128)
End With
End Sub
'双击解锁
Private Sub Yes_DblClick(ByVal Cancel As MSForms.ReturnBoolean)
With Me.IncrementalImpactPricingInput1
.Enabled = True
.BackColor = RGB(255, 255, 255)
End With
With Me.IncrementalImpactFundingInput1
.Enabled = True
.BackColor = RGB(255, 255, 255)
End With
Yes.Value = False
End Sub