Thursday, April 28, 2011

How long your macros run?

Do you know how much time your macro takes to run? Sometimes we create some macros that takes to much time to run but don’t know exactly how much. This code below is useful to use when we get a large of data from an external data source…

Dim strTimeStart as String
Dim strTimeFinish as String
strTimeStart = Time()
[Insert your vba code here]
strTimeFinish = Time()
MsgBox "Your macro takes " & DateDiff("s", strTimeStart, strTimeFinish) & “ seconds to run!”

With this information you can decide if is better to split the code in two or more macros and insert a status message in the middle, or leave like it is and just inform the users that your macro will take “x” minutes to run…
Knowing exactly the time that your macros takes to run you can take advantage to build better and organize your report(s).

No comments:

Post a Comment