0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

時間計測用のVBA

Last updated at Posted at 2025-08-20

メソッドで開始/終了したい場合(クラス版・任意の場所でStop)

CBlockTimer.cls
Option Explicit
Private t0 As Double, lbl As String, active As Boolean

Public Sub Start(Optional ByVal label As String = "", Optional ByVal autoLog As Boolean = True)
    lbl = label: t0 = NowHiRes(): active = autoLog Or True
End Sub

Public Function [Stop](Optional ByVal overrideLabel As String = "") As Double
    If Not active Then Exit Function
    Dim ms As Double, l As String
    ms = (NowHiRes() - t0) * 1000#
    l = IIf(overrideLabel <> "", overrideLabel, lbl)
    Debug.Print "⏱ " & IIf(l <> "", l & ": ", "") & Format(ms, "0.000") & " ms"
    [Stop] = ms: active = False
End Function
呼び出し側.vba
Sub Example_Class()
    Dim m As New CBlockTimer
    m.Start "集計"
    ' ... 処理 ...
    Dim ms As Double: ms = m.Stop()   ' 任意の地点で終了
End Sub
0
0
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
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?