2013-10-22 32 views
-1

我有一个用于获取用户输入的Excel-VBA用户表单。我需要在发生错误时显示此用户表单,以便用户可以重新定义输入值。如何在发生错误时显示用户表单

伪代码:

Sub() 
    userform.Show 
    Call Execute 
End Sub 

Sub Execute() 
    Validate the input 
    If input is wrong 
    MsgBox "reselect the input" 
    -here I need to disply the userform- 
End sub 

我试图GoTo Userform这给了我一个标签未定义错误。有什么建议么?

+1

你的问题是有点不清楚,不完整的,看起来像你希望我们写太多的代码为您服务。如果你真的要求'On Error'解决方案搜索'[VBA] On Error GoTo'在这里在SO或检查[THIS LINK](http://msdn.microsoft.com/en-us/library/office/gg251688% 28V = office.14%29.aspx)。 –

回答

0

我已经创建了一个用户窗体:

enter image description here

在命令按钮点击,对于输入代码检查,并且如果输入是错误的,它显示在消息框中的错误,然后重定向到窗体。

私人小组CommandButton1_Click()

If TextBox1.Value = "" Then 

    MsgBox ("Please provide the value") 

    UserForm1.Show 

    UserForm1.Repaint 

End If 

末次

PS:更改用户窗体为 “假” 的ShowModal属性。

enter image description here

相关问题