VBA記錄當前系統時間並精確到毫秒


想做個功能,點一次按鈕,就在A1記錄一次當前系統時間,要精確到毫秒的。再點一次按鈕就在A2顯示,以此類推!

例如:這個功能可以用來做歌詞記時間!

Sub ttt()
ActiveCell.Select
tt = Timer
h = Int(tt / 3600)
m = Int((tt - 3600 * h) / 60)
s = Int(tt - h * 3600 - m * 60)
ss = Left(tt - Int(tt), 4)
Selection.NumberFormatLocal = "yyyy-mm-dd hh:mm:ss.000"
Selection.Value = h & ":" & m & ":" & s & ss
ActiveCell.Offset(1, 0).Select
End Sub

上面的代碼確實可以實現這個功能,可是還有個問題,當超過一個屏幕的時候,點着點着,按鈕點不到了,excel視圖隨着點擊按鈕新的內容屏幕往下移了,按鈕看不到了,你不能改變光標位置。所以我再次改良如下代碼:

Sub testTime()
Dim tt, n
tt = Timer
n = Range("A65536").End(xlUp).Row
h = Int(tt / 3600)
m = Int((tt - 3600 * h) / 60)
s = Int(tt - h * 3600 - m * 60)
ss = Left(tt - Int(tt), 4)
Cells(n + 1, 1).NumberFormatLocal = "hh:mm:ss.000"
Cells(n + 1, 1) = h & ":" & m & ":" & s & ss
End Sub

這個方法可以完美的記錄歌詞的時間了。

 

參考出處:http://www.excelpx.com/thread-329989-1-1.html


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM