VBA - show clock time with accuracy of less than a second

前端 未结 5 1945
不知归路
不知归路 2020-12-11 08:59

Is there a way to use VBA (excel) to generate a clock time with accuracy to a tenth of a second or less?

eg:

Sub test()
    MsgBox Format(Time, \"hh:         


        
5条回答
  •  孤城傲影
    2020-12-11 09:45

    I have noticed through some trial and error that current time is shown atleast upto 10 milliseconds if you assign a formula to a cell opposed to using the function directly in vba. I generally use the NOW() function for current time.

    If my code is as follows:

    sub test()
    cells(1,1)=now()
    end sub
    

    then cell A1 shows time upto seconds, not milliseconds (time would be shown as 10:38:25.000)

    if I use this code:

    sub test()
    cells(2,1).formula "=now()"
    cells(1,1)=cells(2,1)
    end sub
    

    Then time is shown upto milliseconds in A1 (time would be shown as 10:38:25.851)

提交回复
热议问题