2013-10-22 33 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

相關問題