我有一个UserForm,当条件存在时,它在循环中打开和关闭。用户可以单击多个按钮来执行操作。问题是用户的不可预测性。其中一个问题是,用户不是单击其中一个按钮,而是单击UserForm顶部的close window按钮,这将继续循环,而不执行任何操作。
-编辑
这个按钮有没有一个事件,我可以用它来执行代码,这样我就可以让它执行与表单本身上的cancel按钮相同的操作。我本身不需要隐藏或禁用它。
发布于 2016-01-01 21:40:46
例如,您可以将下面的宏添加到UserForms代码模块:
Private Sub UserForm_QueryClose(Cancel As Integer, CloseMode As Integer)
If CloseMode = vbFormControlMenu Then
Cancel = True
MsgBox "You can't close the dialog like this!"
End If
End Sub发布于 2018-08-13 21:48:02
你可以只关注一个按钮,而不是MsgBox:
Private Sub UserForm_QueryClose(Cancel As Integer, CloseMode As Integer)
If CloseMode = vbFormControlMenu Then
Cancel = True
Me.Close_Button.SetFocus
End If
End Sub编辑:我发现了一个更好的选择:
Private Sub UserForm_QueryClose(Cancel As Integer, CloseMode As Integer)
' YOUR CODE HERE (Just copy whatever the close button does)
If CloseMode = vbFormControlMenu Then
Cancel = False
End If
End Subhttps://stackoverflow.com/questions/34556520
复制相似问题