Learn Macros‎ > ‎VBA Macros‎ > ‎

Calculate how long macro runs

posted Jun 19, 2011, 8:28 AM by Ayush Jain   [ updated Jun 19, 2011, 9:12 AM ]

If you want to know the duration of macro execution , You can use the below macro :

Sub TimeTaken()

    Dim strTime1 As String, strTime2 As String

    strTime1 = Format(Now(), "mm-dd-yyyy hh:MM:ss")

    '[Write your code here]

    strTime2 = Format(Now(), "mm-dd-yyyy hh:MM:ss")

    MsgBox "Elapsed Time = " & DateDiff("n", strTime1, strTime2) & _
    " Minutes and " & DateDiff("s", strTime1, strTime2) & " Seconds"

End Sub

 
Tags : Macro Duration, Time Difference, Time Taken in Macro execution
Comments