引用:How to Detect vba InputBox "Cancel" or "X" clicked other than detecting null input ?
You need to understand the built-in function. If you cancel the input, it will return a Zero length string. The Cancel button return an empty string. There is no Args for the Cancel button. So you cannot detect the Cancel button being press by the user.
- “取消”或“X”测试是否为Null
Sub test() On Error Resume Next Dim rng As Object rng = Application.InputBox("Select Range:", , , , , , , 8) Dim b As Boolean b=isNull(rng) MsgBox "Is Null ---" & b End Sub
不是Null
- “取消”或“X”测试是否为Nothing
Sub test() On Error Resume Next Dim rng As Object rng = Application.InputBox("Select Range:", , , , , , , 8) Dim b As Boolean If rng Is Nothing Then b = True Else b = False End If MsgBox "Is nothing ---" & b End Sub
是Nothing
- 什么是Null,什么是Nothing
要判断Nothing的,必须是一个对象(Object),未初始化的对象是Nothing
Null 必须是一个变量。尚未完全理解。。。