Wednesday, October 7, 2015

How to calculate and show total execution time taken by a VBA code?

It is very important to know total execution time taken by any VBA code. Because, it's very important parameter to optimize performance of the code. Also, it is very useful to determine time complexity of the project. Based on this execution time calculation it very ease to define project complexity.

In order to consider VBA code execution time requirement in the project. I have written few line of codes which will very useful to calculate total execution time taken by any VBA code.



Here is the VBA code to get total execution time taken by any VBA code:


Sub Execution_Time_Calculation()
' Author: Dreams24
' Written for VBA Tricks and tips blog
' https://vbatricksntips.com


    T1 = Timer

    
    Application.ScreenUpdating = False
    Application.DisplayAlerts = False
 
        'Put your code here
 
    Application.ScreenUpdating = True
    Application.DisplayAlerts = True
    
    T2 = Timer
    
    MsgBox "Task Completed Successfully !!! " & "Time Taken: " & Format((T2 - T1) / 86400, "HH:MM:SS"), vbInformation

End Sub

No comments: