如何检测用户是否选择取消InputBox VBA Excel [英] How to detect if user select cancel InputBox VBA Excel
问题描述
像
如果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
会告诉他们删除默认字符串时取消的用户,或者点击取消。
请参阅 http://msdn.microsoft.com/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 Sub
Would tell the user they canceled when they delete the default string, or they click cancel.
See http://msdn.microsoft.com/en-us/library/6z0ak68w(v=vs.90).aspx
这篇关于如何检测用户是否选择取消InputBox VBA Excel的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!