VBA Function: Time
The VBA Time function returns the current time of the system.
Usage:
Time
Examples of Usage
Save the time returned by the Time function in cell A1:
Sub example()
Range("A1") = Time
End Sub
Display the time returned by the Time function in text format:
Sub example()
MsgBox Format(Time, "h:nn AM/PM") 'Returns, for example: 1:24 PM
End Sub
Perform an action only if it is at least 5:00 PM:
Sub example()
If Hour(Time) >= 17 Then
MsgBox "The day is almost over!"
End If
End Sub
The function that returns the current date as well as the current time is the Now function.