像 如果str = vbCancel然后退出sub
目前,用户可以点击确定或取消,但程序仍然运行
str = InputBox(Prompt:=输入日期MM / DD / YYY,_ 标题:=日期确认,默认值:=日期) / code>
解决方案如果用户单击取消,返回零长度的字符串。您不能区分这一点,而不能输入一个空字符串。然而,您可以制作自己的自定义InputBox类...
您的示例
Private Sub test() Dim Str As String Str = InputBox(输入日期MM / DD / YYY,Date Confirmation,现在)如果Str = vbNullString Then MsgBox(用户已取消!)如果 End Sub会告诉他们删除默认字符串时取消的用户,或者点击取消。
请参阅 msdn.microsoft/en-us/library/6z0ak68w(v = vs90)。 aspx
I have an input box asking user to enter a date. How do I let the program know to stop if the user click cancel or close the input dialog instead of press okay.
Something like if str=vbCancel then exit sub
Currently, user can hit OK or Cancel but the program still runs
str = InputBox(Prompt:="Enter Date MM/DD/YYY", _ Title:="Date Confirmation", Default:=Date)
解决方案If the user clicks Cancel, a zero-length string is returned. You can't differentiate this from entering an empty string. You can however make your own custom InputBox class...
Your example
Private Sub test() Dim Str As String Str = InputBox("Enter Date MM/DD/YYY", "Date Confirmation", Now) If Str = vbNullString Then MsgBox ("User canceled!") End If End SubWould tell the user they canceled when they delete the default string, or they click cancel.
See msdn.microsoft/en-us/library/6z0ak68w(v=vs.90).aspx
更多推荐
如何检测用户是否选择取消InputBox VBA Excel
发布评论