how do i display the time in a vba worksheet?

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 :
 
P

papou

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
 
D

Devitt

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.
 
P

papou

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
 
D

Devitt

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
 
P

papou

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
 
D

Devitt

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
 
Top