VBA Time 函数返回当前系统时间。
Time
让我们将 Time 函数获得的时间保存在单元格 A1 中:
Sub TimeExample1()
Range("A1") = Time
End Sub
以文本格式显示Time函数获得的时间:
Sub TimeExample2()
MsgBox Format(Time, "hh\hnn") '返回,例如:13h24
End Sub
仅当现在至少 17:00 时我们才会执行该操作:
Sub TimeExample3()
If Hour(Time) >= 17 Then
MsgBox "这一天快结束了!"
End If
End Sub