方法介绍,利用 StrPtr() 函数。
StrPtr:返回真正的UNICODE字符串缓冲区的地址
直接上代码
Option Explicit
Sub ReturnInput()
Dim Key As String
Key = InputBox("请输入关键词", "这是一个测试")
If StrPtr(Key) = 0 Then
MsgBox "点击了取消或是直接关闭了窗口。"
ElseIf StrPtr(Key) <> 0 Then
If Len(Key) = 0 Then
MsgBox "输入了空白值。"
ElseIf Len(Key) <> 0 Then
MsgBox "输入的Key值为:" & Key
End If
End If
End Sub