相互触发的多个用户表单; UserForm_QueryClose 未按预期工作
Multiple UserForms that trigger each other; UserForm_QueryClose not working as expected
我有 5 个用户窗体,其中一些会根据第一个用户窗体的输入而激活。
第一个用户窗体代码如下。
Private Sub OptionButton1_Click()
If OptionButton1.Value = True Then
WsName = "CAT"
Unload Me
End If
End Sub
Private Sub OptionButton2_Click()
If OptionButton2.Value = True Then
WsName = "DOG"
Unload Me
End If
End Sub
Private Sub OptionButton3_Click()
If OptionButton3.Value = True Then
WsName = "CATDOG"
Unload Me
End If
End Sub
Private Sub OptionButton4_Click()
If OptionButton4.Value = True Then
WsName = "DOGCAT"
Unload Me
End If
End Sub
Private Sub UserForm_Initialize()
Me.StartUpPosition = 0
Me.Top = Application.Top + 250
Me.Left = Application.Left + Application.Width - Me.Width - 600
End Sub
Private Sub UserForm_QueryClose(Cancel As Integer, CloseMode As Integer)
End
End Sub
当我按红色 "X" 结束调用 UserForm 的整个模块时,模块退出,我很高兴。当我按下用户窗体上的选项之一时,例如 OptionButton1.Value = True 然后代码也会退出模块,我很难过。我究竟做错了什么?我希望用户能够在任何用户窗体中的任何时候按红色 "X" 以关闭模块并跳出代码。
这个问题的答案是
Private Sub UserForm_QueryClose(Cancel As Integer, CloseMode As Integer)
If
OptionButton1.Value = False And OptionButton2.Value = False OptionButton3.Value =
False And OptionButton4.Value = False Then
End
End If
End Sub
我有 5 个用户窗体,其中一些会根据第一个用户窗体的输入而激活。
第一个用户窗体代码如下。
Private Sub OptionButton1_Click()
If OptionButton1.Value = True Then
WsName = "CAT"
Unload Me
End If
End Sub
Private Sub OptionButton2_Click()
If OptionButton2.Value = True Then
WsName = "DOG"
Unload Me
End If
End Sub
Private Sub OptionButton3_Click()
If OptionButton3.Value = True Then
WsName = "CATDOG"
Unload Me
End If
End Sub
Private Sub OptionButton4_Click()
If OptionButton4.Value = True Then
WsName = "DOGCAT"
Unload Me
End If
End Sub
Private Sub UserForm_Initialize()
Me.StartUpPosition = 0
Me.Top = Application.Top + 250
Me.Left = Application.Left + Application.Width - Me.Width - 600
End Sub
Private Sub UserForm_QueryClose(Cancel As Integer, CloseMode As Integer)
End
End Sub
当我按红色 "X" 结束调用 UserForm 的整个模块时,模块退出,我很高兴。当我按下用户窗体上的选项之一时,例如 OptionButton1.Value = True 然后代码也会退出模块,我很难过。我究竟做错了什么?我希望用户能够在任何用户窗体中的任何时候按红色 "X" 以关闭模块并跳出代码。
这个问题的答案是
Private Sub UserForm_QueryClose(Cancel As Integer, CloseMode As Integer)
If
OptionButton1.Value = False And OptionButton2.Value = False OptionButton3.Value =
False And OptionButton4.Value = False Then
End
End If
End Sub