1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

【Excel VBA】時分秒ミリ秒取得【関数サンプル】

Last updated at Posted at 2019-08-01
VBA
Rem
Rem 関数呼び出し例
Rem
Private Sub FncCall()
    '使用例1:時間
    Debug.Print GetTime()

    '使用例2:日付+時間
    Debug.Print Format(Date, "yyyy/mm/dd") & " " & GetTime()
End Sub
Rem
Rem 時分秒ミリ秒
Rem
Public Function GetTime() As String

    Dim timeHmsS: timeHmsS = Timer
    Dim timeHms: timeHms = Int(timeHmsS)
    Dim timeS: timeS = timeHmsS - timeHms

    Dim hour: hour = Int(timeHms / (60 * 60))
    Dim minute: minute = Int((timeHms - (hour * 60 * 60)) / 60)
    Dim second: second = timeHms - (hour * 60 * 60 + minute * 60)
    Dim millisecond: millisecond = Left(Right(CStr(timeS), Len(timeS) - 1), 4)

    GetTime = Format(hour, "00") & ":" & Format(minute, "00") & ":" & Format(second, "00") & Format(millisecond, ".000")

End Function
1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?