vba 如何刷新表单?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/22811067/
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 refresh a form?
提问by HumanlyRespectable
I have a userform with a button on it. I want the button to "refresh" the form, in other words I want the form to end, and then reopen.
我有一个带有按钮的用户表单。我希望按钮“刷新”表单,换句话说,我希望表单结束,然后重新打开。
The code below won't work because the form/macro has already ended, but I want the button to perform this task or similar.
下面的代码将不起作用,因为表单/宏已经结束,但我希望按钮执行此任务或类似任务。
sub command1.click()
end
userform1.show
end sub
I have checked and tried most or all the options I can choose from for a userform to "refresh". Is this even possible?
我已经检查并尝试了大多数或所有我可以选择的用户表单“刷新”选项。这甚至可能吗?
回答by Siddharth Rout
Here is a very simple way. Simply Re-Initialze the Userform using the UserForm_Initialize
这里有一个非常简单的方法。只需使用UserForm_Initialize
Private Sub UserForm_Initialize()
TextBox1.Text = "" '<~~ Just an Example
'
'~~> Put here the code to re-initialize the userform which will refresh it
'
End Sub
Private Sub CommandButton1_Click()
TextBox1.Text = "Sid"
MsgBox "Re-Initialzing the Userform"
UserForm_Initialize
End Sub
回答by Bk Panda
Private Sub CommandButton1_Click()
Unload Me
UserForm1.Show
End Sub