我使用以下代码(在Excel 2013 Windows 8.1中):
Private Sub txtDateBox_exit(ByVal cancel As msforms.ReturnBoolean)
If IsDate(txtDateBox.Value) = False Then
MsgBox "Enter a Valid Date, such as Jan 23, 2015"
txtDateBox.SetFocus
End If
End Sub
如果我输入了一个无效的日期,msgbox弹出,但是当sub退出时,光标已经移动到我