You can use GetTickCount, which should be declared as:
' Declare the Windows call to retrieve the time in milliseconds
Declare Function GetTickCount Lib "kernel32" Alias "GetTickCount" () As Long
then you call this function before and after the macro and calculate the difference, which will give you the macro execution time in milliseconds.
Example:
' Declare the Windows call to retrieve the time in milliseconds
Declare Function GetTickCount Lib "kernel32" Alias "GetTickCount" () As Long
Sub Test
Dim t1 As Long, t2 As Long
t1=GetTickCount
'Call MyMacro
t2=GetTickCount
Debug.Print "Time = " & (t2-t1)
End Sub
Another method using functions already in the code is as follows:
Sub TimeTest() Dim startTime As Date Dim endTime As Date Dim diffTime As Date
' Wait some duration startTime = Time ' Record starting time Wait(5) ' Your processing here... endTime = Time ' Record end time ' Find the difference between the two diffTime = endTime - startTime
' In "Date" variables the whole value gives the date, while the fraction ' is the time of day. Here the difference is scaled by 24 hours, ' 60 minutes, and 60 seconds to obtain the difference in seconds. Debug.Print CDbl(diffTime) * 24*60*60; " seconds."
End Sub
Answers
Example:
Yuri
The output from this on my machine is:
Carlos