TOP

VBA Function: Time

Description

The VBA Time function returns the current system time.


Syntax Time

Time

VBA Time Example

Let's store the time received by the Time function in cell A1:

SubTimeExample1()

      Range("A1") = Time
    
end sub

Displaying the time received by the Time function in text format:

SubTimeExample2()

      MsgBox Format(Time, "hh\hnn") 'Returns, for example: 13:24
    
end sub

Perform the action only if it is at least 17:00 now:

SubTimeExample3()

      If Hour(Time) >= 17 Then
          MsgBox "The day is almost over!"
      End if
    
end sub
The function that returns the current date and current time is the NOW function.