0

Please show me on how to display system time with running seconds in userform - vba excel 2010

Just like visual basic timer object - but I cant find any like this in macro

Thanks...

2 Answers 2

3

you can do this as below (found on Ozgrid.Com Forums) :

in a UserForm with a label called Label1 put the below code

Private Sub UserForm_Initialize()
    Me.Label1 = Time
    Application.OnTime Time + TimeValue("00:00:01"), "Live_time"
End Sub


Private Sub UserForm_Terminate()
    Application.OnTime Time + TimeValue("00:00:01"), "Live_time", , False
End Sub

in a Public module, put this code:

Sub Live_time()
    Application.OnTime Time + TimeValue("00:00:01"), "Live_time"
    UserForm1.Label1 = Time
    UserForm1.Repaint
End Sub

then run the form with the label on it.

Sign up to request clarification or add additional context in comments.

1 Comment

I'd stick with this solution as it looks the simplest. But I don't believe you need to additionally run the onTime event in the UserForm. Just calling Live_time() should do the trick.
0

you could also write this code
Application.OnTime Time + TimeValue("00:00:01"), "Live_time" UserForm1.Label1 = Time on the initialize event of the userform.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.