vba 隐藏后如何返回或重新显示用户表单?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/20068412/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to go back or re-display Userform after hiding it?
提问by L42
I have this code in one command button in UserForm2:
我在 UserForm2 的一个命令按钮中有此代码:
Private Sub CButton1_Click()
UserForm1.Show
Me.Hide
End Sub
Now, Userform1
is shown.
Then I have another code in one command button in Userform1:
现在,Userform1
显示。
然后我在 Userform1 的一个命令按钮中有另一个代码:
Private Sub CButton2_Click()
UserForm2.Show
Unload Me
End Sub
This throws up a:
这会抛出一个:
Runtime Error: Form already displayed; can't show modally
运行时错误:表单已显示;不能模态显示
How do I do this properly?
How do I go back to the previous Userform
after hiding or unloading it?
我该如何正确执行此操作?隐藏或卸载后
如何返回上一个Userform
?
回答by Octavio
I think the problem is the order of the statements. I found out by using the debugger that when I had the Show statements before the Hide or Unload, these last are not executed.
我认为问题在于语句的顺序。我通过使用调试器发现,当我在 Hide 或 Unload 之前有 Show 语句时,最后这些语句不会被执行。
Try this
尝试这个
' on UserForm2
Private Sub CommandButton1_Click()
Me.Hide
UserForm1.Show
End Sub
' on UserForm1
Private Sub CommandButton1_Click()
Me.Hide
UserForm2.Show
End Sub
回答by Huy Pham
Change to this:
改成这样:
Private Sub CButton1_Click()
Me.Hide
UserForm1.Show
Unload Me
End Sub
Private Sub CButton2_Click()
Me.Hide
UserForm2.Show
Unload Me
End Sub