Excel VBA

Is there a way to build a timer into the code to let you know how long the program ran?
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.


pls refer to http://stackoverflow.com/questions/198409/how-do-you-test-running-time-of-vba-code

or the simple

Dim start_time, end_time
start_time = Now()
' Do your stuff here '
end_time = Now()
MsgBox(DateDiff("s", start_time, end_time))

Open in new window

Martin LissOlder than dirtCommented:
If you want to find out how long the workbook was open then in the VBE (click Alt+F11 to get there) and if you don't already have a module go to Insert|Module and add one. At the top of the module put

Public gStartTime As Date

Open in new window

Then add this code in 'ThisWorkbook"

Private Sub Workbook_BeforeClose(Cancel As Boolean)
Dim intMin As Integer
Dim intSec As Integer
intSec = DateDiff("s", gStartTime, Now())
intMin = intSec \ 60
MsgBox "The program ran for " & DateDiff("m", gStartTime, Now()) & " minutes and " & intSec & " seconds"
End Sub

Private Sub Workbook_Open()
gStartTime = Now()
End Sub

Open in new window

Here's a workbook that does it.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Office

From novice to tech pro — start learning today.