how do i display the time in a vba worksheet?

  • Thread starter Thread starter Devitt
  • Start date Start date
D

Devitt

I can get the time up but i want to have the seconds ticking away.. th
best i can get is chucking it on a 'mousemove' which doesn't refres
very smoothly.. can ne1 help meh?

This is what i have that i need improving on:

Private Sub MultiPage1_MouseMove(ByVal Index As Long, ByVal Button A
Integer, ByVal Shift As Integer, ByVal X As Single, ByVal Y As Single)
lbldate = Time
End Sub

As you can see it sucks :
 
Hello Devitt
I suggest you use OnTime, here is a sample code (please amend accordingly):
1 - in a standard module paste this:
Public Sub Update_time()
If UserForm1.Visible = False Then Exit Sub
UserForm1.Lbldate = Format(Now, "dddd dd mm yyyy HH:MM:SS")
Application.OnTime Now + TimeValue("00:00:01"), "Update_time", , True
End Sub
2 - in the Initialize event of your userform paste this:
Private Sub UserForm_Initialize()
UserForm1.Lbldate = Format(Now, "dddd dd mm yyyy HH:MM:SS")
Application.OnTime Now + TimeValue("00:00:01"), "Update_time", , True
End Sub

This method will refresh the time value (every second) in your userform
until its closed again.
HTH
Cordially
Pascal
 
Cheers for that m8..
It worked sorta but still doesn't refresh..

This is how it is in my project now:

Public Sub Update_time()
If frmdave.Visible = False Then Exit Sub
frmdave.lbldate = Format(Now, "dddd dd mm yyyy HH:MM:SS")
Application.OnTime Now + TimeValue("00:00:01"), "Update_time", , True
End Sub

Private Sub userform_Initialize()
frmdave.lbldate = Format(Now, "dddd dd mm yyyy HH:MM:SS")
Application.OnTime Now + TimeValue("00:00:01"), "Update_time", , True
End Sub



If it makes any differance im using excel 2003.
 
Did you place the "Update_Time" routine into a standard module and NOT with
the Userform_Initialize event?

BTW: I am also using Excel 2003 and it works.
HTH
Cordially
Pascal
 
Did you place the "Update_Time" routine into a standard module and NO
with
the Userform_Initialize event?

Haha... no... but it works perfect now THANK YOU!!!!

I jus gta get the old 'vbyesno' msgbox working now lol

(if u dont mind helping, all i want it to do is when i click yes i
runs some code... i managed it at college but now i cant
 
No I don't mind helping when I can ;-)
Sub GotIt()
If MsgBox("Do you wish to launch the macro?", vbYesNo + vbQuestion, "Please
answer") = vbYes Then macro1
End Sub
Sub macro1()
MsgBox "Macro1 running"
End Sub

HTH
Cordially
Pascal
 
omg its all flooding back now...
All i had to do was add 'if' to 1 line of my code and it worked...
i jus had msgbox "blahblahblah",etc,etc and had the 'if' on the lin
below
thank you loads m8 you have made a big differance to mah project!!
Peace ou
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top